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 eth1
ip link set dev eth1 up
ip link add dev eth1.3 link eth1 type vlan id 3
ip link add dev eth1.5 link eth1 type vlan id 5
The ip link add commands added interfaces "eth1.3" and "eth1.5", which you can
then configure:
ip addr add 1.2.3.4/24 dev eth1.3
ip link set dev eth1.3 up
ip addr add 10.100.2.3/16 dev eth1.5
ip link set dev eth1.5 up
The traffic that flows out of eth1.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 eth1.3 and everything to 10.100.x.x through eth1.5. Traffic to 198.51.1xx.x flows through eth1 (without a VLAN tag).
To remove one of the VLAN interfaces:
ip link set dev eth1.3 down
ip link delete eth1.3 type vlan