Setup VLAN interface on CentOS

less than 1 minute read

There are some scenarios where we want to assign multiple IPs from different VLAN on the same Ethernet card (nic) on Linux servers (CentOS / RHEL). This can be done by enabling VLAN tagged interface.

Let’s assume we have a Linux Server, there we have one Ethernet card (em1).

So attach VLANs 4 tag to NIC em1 using the ip command

ip link add link em1 name vlan4 type vlan id 4

To view the VLAN, issue the following command:

ip -d link show vlan4

Bring up the interface using below ip command:

ip link set dev vlan4 up

Now we can assign the IP address to tagged interface from their respective VLANs using beneath ip command,

ip addr add dev vlan4

To delete created VLAN interface use next command

ip link delete dev vlan4@em1

It will work to the next reboot. For saving the configuration edit the network settings stored in directory /etc/sysconfig/network-scripts/.

Additional information