Configuring Interface-based VLAN Assignment (Statically Configured Interface Type)
Context
Interface-based VLAN assignment is the simplest and most effective method. VLANs are assigned based on interfaces. After an interface is added to a VLAN, the interface can forward packets from the VLAN. Interface-based VLAN assignment allows hosts in the same VLAN to communicate and prevents hosts in different VLANs from communicating, thereby limiting broadcast packets to a single VLAN.
Access interface
A switch processes only tagged frames, but an access interface connected to devices can only receive and send untagged frames. Therefore, you must configure the default VLAN for the access interface to add the access interface to that VLAN. Then the access interface can add a VLAN tag to received frames.
An access interface needs to process only untagged frames. If a user connects a switching device to a user-side interface without permission, the user-side interface may receive tagged frames. You can configure the user-side interface to discard tagged frames, preventing unauthorized access.
Trunk interface
When a trunk interface connects to a device such as an AP or a voice terminal that can receive and send tagged and untagged frames simultaneously, you need to configure the default VLAN for the trunk interface so that the trunk interface can add the VLAN tag to untagged frames.
Hybrid interface
When a hybrid interface connects to an AP, a voice terminal, a hub, a host, or a server that sends untagged frames to the switch, you need to configure the default VLAN for the hybrid interface so that the hybrid interface can add the VLAN tag to untagged frames.
Frames sent by a switch all carry VLAN tags. In some scenarios, hybrid interfaces are needed for removing VLAN tags from frames sent by the switch. For example, in VLAN stacking scenarios, the outer VLAN tags of packets from multiple VLANs on an ISP network need to be removed before they enter a user network. A trunk interface allows untagged packets from only one VLAN, so the interface must be configured as a hybrid interface. For details about VLAN stacking, see QinQ Configuration.
By default, the type of an interface is negotiation-auto.
Procedure
- Configuring the default VLAN for an access interface
Run:
system-view
The system view is displayed.
Run:
vlan vlan-id
A VLAN is created and the VLAN view is displayed, or the view of an existing VLAN is displayed.
Run:
quit
Return to the system view.
Run:
interface interface-type interface-number
The view of the Ethernet interface to be added to the VLAN is displayed.
Run:
port link-type access
The Ethernet interface is configured as the access interface.
Run:
port default vlan vlan-id
The default VLAN is configured for the interface and the interface is added to the specified VLAN.
(Optional) Run:
port discard tagged-packet
The interface is configured to discard incoming tagged packets.
- Configuring the default VLAN for a trunk interface
Run:
system-view
The system view is displayed.
Run:
vlan vlan-id
A VLAN is created and the VLAN view is displayed, or the view of an existing VLAN is displayed.
Run:
quit
Return to the system view.
Run:
interface interface-type interface-number
The view of the Ethernet interface to be added to the VLAN is displayed.
Run:
port link-type trunk
The Ethernet interface is configured as the trunk interface.
Run:
port trunk allow-pass vlan { { vlan-id1 [ to vlan-id2 ] } &<1-10> | all }
The interface is added to the specified VLAN.
(Optional) Run:
port trunk pvid vlan vlan-id
The default VLAN is configured for the trunk interface.
When the VLAN allowed by an interface is the default VLAN of the interface, packets from the VLAN are forwarded in untagged mode.
- Configuring the default VLAN for a hybrid interface
Run:
system-view
The system view is displayed.
Run:
vlan vlan-id
A VLAN is created and the VLAN view is displayed, or the view of an existing VLAN is displayed.
Run:
quit
Return to the system view.
Run:
interface interface-type interface-number
The view of the Ethernet interface to be added to the VLAN is displayed.
Run:
port link-type hybrid
The Ethernet interface is configured as the hybrid interface.
Run the following commands as required.
Run:
port hybrid untagged vlan { { vlan-id1 [ to vlan-id2 ] } &<1-10> | all }
The hybrid interface is added to the VLAN in untagged mode.
Run:
port hybrid tagged vlan { { vlan-id1 [ to vlan-id2 ] } &<1-10> | all }
The hybrid interface is added to the VLAN in tagged mode.
(Optional) Run:
port hybrid pvid vlan vlan-id
The default VLAN is configured for the hybrid interface.
Configuration Tips
Creating VLANs in a batchTo create multiple VLANs in a batch, run the vlan batch command in the system view.
- Create 10 contiguous VLANs: VLAN 11 to VLAN 20.
<HUAWEI> system-view [HUAWEI] vlan batch 11 to 20
- Create 10 incontiguous VLANs in a batch: VLAN 10, VLANs 15 to 19, VLAN 25, VLANs 28 to VLAN 30.
<HUAWEI> system-view [HUAWEI] vlan batch 10 15 to 19 25 28 to 30
You can create a maximum of 10 incontiguous VLANs or VLAN range at one time. If there are more than 10 VLANs, run this command multiple times. For example, the vlan batch 10 15 to 19 25 28 to 30 command creates four incontiguous VLAN ranges.
When multiple VLANs are created on the device, you can configure names for the VLANs to facilitate management. After a name is configured for a VLAN, you can directly enter the VLAN view using the name.
# Set the name of VLAN 10 to huawei.
<HUAWEI> system-view [HUAWEI] vlan 10 [HUAWEI-vlan10] name huawei [HUAWEI-vlan10] quit
# After a name is configured for a VLAN, you can directly enter the VLAN view using the name.
[HUAWEI] vlan vlan-name huawei [HUAWEI-vlan10] quitAdding interfaces to a VLAN in a batch
Use a port group to perform the same VLAN configuration for multiple Ethernet interfaces. To add access interfaces to a VLAN in a batch, you can also run the port interface-type { interface-number1 [ to interface-number2 ] }&<1-10> command in the VLAN view. For details, see How Do I Add Interfaces to a VLAN in a Batch?.
Restoring the default VLAN configuration of an interfaceIf the VLAN planning of an interface is changed, you need to delete the original VLAN configuration of the interface. If many incontiguous VLANs are configured on the interface, you need to delete the original VLAN configuration multiple times. To reduce the workload, you can restore the default VLAN configuration of the interface. For details, see How Do I Restore the Default VLAN Configuration of an Interface?.
Changing the interface typeWhen the interface planning changes or the current interface type is different from the configured one, the interface type needs to be changed. For details, see How Do I Change the Link Type of an Interface?.
Deleting a VLANIf a VLAN is not in use, you are advised to delete it immediately to save VLAN resources and reduce packets on a network. For details, see How Do I Delete a Single VLAN or VLANs in a Batch?.