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. But for this to happen first we must make sure multiple VLANs are attached to port on switch or in other words we can say we should configure trunk port by adding multiple VLANs on switch.
Let’s assume we have a Linux Server, there we have two Ethernet cards (enp0s3 & enp0s8), first NIC ( enp0s3 ) will be used for data traffic and second NIC (enp0s8) will be used for control / management traffic. For Data traffic I will using multiple VLANs (or will assign multiple IPs from different VLANs on data traffic ethernet card).
I am assuming the port from switch which is connected to my server data NIC is configured as trunk port by mapping the multiple VLANs to it.
Following are the VLANs which is mapped to data traffic Ethernet Card (NIC):
- VLAN ID (200), VLAN N/W = 184.108.40.206/24
- VLAN ID (300), VLAN N/W = 220.127.116.11/24
To use VLAN tagged interface on CentOS 7 / RHEL 7 / CentOS 8 /RHEL 8 systems, kernel module 8021q must be loaded.
Use the following command to load the kernel module “8021q”
[[email protected] ~]# lsmod | grep -i 8021q [[email protected] ~]# modprobe --first-time 8021q [[email protected] ~]# lsmod | grep -i 8021q 8021q 29022 0 garp 14384 1 8021q mrp 18542 1 8021q [[email protected] ~]#
Use below modinfo command to display information about kernel module “8021q”
[[email protected] ~]# modinfo 8021q filename: /lib/modules/3.10.0-327.el7.x86_64/kernel/net/8021q/8021q.ko version: 1.8 license: GPL alias: rtnl-link-vlan rhelversion: 7.2 srcversion: 2E63BD725D9DC11C7DA6190 depends: mrp,garp intree: Y vermagic: 3.10.0-327.el7.x86_64 SMP mod_unload modversions signer: CentOS Linux kernel signing key sig_key: 79:AD:88:6A:11:3C:A0:22:35:26:33:6C:0F:82:5B:8A:94:29:6A:B3 sig_hashalgo: sha256 [[email protected] ~]#
Now tagged (or mapped) the VLANs 200 and 300 to NIC enp0s3 using the ip command
[[email protected] ~]# ip link add link enp0s3 name enp0s3.200 type vlan id 200
Bring up the interface using below ip command:
[[email protected] ~]# ip link set dev enp0s3.200 up
Similarly mapped the VLAN 300 to NIC enp0s3
[[email protected] ~]# ip link add link enp0s3 name enp0s3.300 type vlan id 300 [[email protected] ~]# ip link set dev enp0s3.300 up [[email protected] ~]#
Now view the tagged interface status using ip command:
Now we can assign the IP address to tagged interface from their respective VLANs using beneath ip command,
[[email protected] ~]# ip addr add 18.104.22.168/24 dev enp0s3.200 [[email protected] ~]# ip addr add 22.214.171.124/24 dev enp0s3.300
Use below ip command to see whether IP is assigned to tagged interface or not.
All the above changes via ip commands will not be persistent across the reboot. These tagged interfaces will not be available after reboot and after network service restart
So, to make tagged interfaces persistent across the reboot then use interface ifcfg files
Edit interface (enp0s3) file “/etc/sysconfig/network-scripts/ifcfg-enp0s3” and add the following content,
Note: Replace the interface name that suits to your env,
[[email protected] ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 TYPE=Ethernet DEVICE=enp0s3 BOOTPROTO=none ONBOOT=yes
Save & exit the file
Create tagged interface file for VLAN id 200 as “/etc/sysconfig/network-scripts/ifcfg-enp0s3.200” and add the following contents to it.
[[email protected] ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3.200 DEVICE=enp0s3.200 BOOTPROTO=none ONBOOT=yes IPADDR=126.96.36.199 PREFIX=24 NETWORK=188.8.131.52 VLAN=yes
Save & exit the file
Similarly create interface file for VLAN id 300 as “/etc/sysconfig/network-scripts/ifcfg-enp0s3.300” and add the following contents to it
[[email protected] ~]# vi /etc/sysconfig/network-scripts/ifcfg-enp0s3.300 DEVICE=enp0s3.300 BOOTPROTO=none ONBOOT=yes IPADDR=184.108.40.206 PREFIX=24 NETWORK=220.127.116.11 VLAN=yes
Save and exit file and then restart network services using the beneath command,
[[email protected] ~]# systemctl restart network [[email protected] ~]#
Now verify whether tagged interface are configured and up & running using the ip command,
That’s all from this article, I hope you got an idea how to configure and enable VLAN tagged interface on CentOS 7 / 8 and RHEL 7 /8 Severs. Please do share your feedback and comments.