Example: Creating two VLANs
VLANs are allocated in an existing interface that represents a physical Ethernet LAN.
The following example creates two VLANs, one with ID 3 and one with ID 5.
ip addr add 198.51.160.23/19 dev ence400
ip link set dev ence400 up
ip link add dev ence400.3 link ence400 type vlan id 3
ip link add dev ence400.5 link ence400 type vlan id 5
The ip link add commands added interfaces ence400.3and
ence400.5, which you can then configure:
ip addr add 1.2.3.4/24 dev ence400.3
ip link set dev ence400.3 up
ip addr add 10.100.2.3/16 dev ence400.5
ip link set dev ence400.5 up
The traffic that flows out of ence400.3 is in the VLAN with
ID=3. This traffic is not received by other stacks that listen to VLANs with ID=4.The internal routing table ensures that every packet to 1.2.3.x goes out through ence400.3 and everything to 10.100.x.x through ence400.5. Traffic to 198.51.1xx.x flows through ence400 (without a VLAN tag).
To remove one of the VLAN interfaces:
ip link set dev ence400.3 down
ip link delete ence400.3 type vlan