Configure Multiple VLANs and IP Addresses on a Single NIC in CentOS/RHEL
This guide explains how to enable VLAN tagging on a Linux server, create VLAN interfaces for different subnets, assign IP addresses, and make the configuration persistent on CentOS/RHEL systems using kernel modules, ip commands, and network‑script files.
In scenarios where a Linux server (CentOS/RHEL) needs to host multiple IP addresses from different VLANs on the same physical NIC, you must first ensure the switch port is configured as a trunk and the required VLANs are created.
Load the 8021q Kernel Module
VLAN tagging on CentOS 7/8 and RHEL 7/8 requires the 8021q kernel module. Verify it is not loaded, then load it:
# lsmod | grep -i 8021q # no output means not loaded
# modprobe --first-time 8021q
# lsmod | grep -i 8021q # should show the moduleYou can view module details with:
# modinfo 8021qCreate VLAN Interfaces
Assume the data‑traffic NIC is ens33. Create VLAN 200 and VLAN 300 on this interface:
# ip link add link ens33 name ens33.200 type vlan id 200
# ip link add link ens33 name ens33.300 type vlan id 300Bring the new interfaces up:
# ip link set ens33.200 up
# ip link set ens33.300 upAssign IP Addresses
Allocate IPs from the respective subnets:
# ip address add 172.168.10.51/24 dev ens33.200
# ip address add 172.168.20.51/24 dev ens33.300At this point the VLAN interfaces work, but the configuration will disappear after a reboot.
Persist Configuration with ifcfg Files
Edit the main NIC configuration to disable automatic IP assignment:
# vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet
BOOTPROTO=none
DEVICE=ens33
ONBOOT=yesCreate configuration files for each VLAN:
# vim /etc/sysconfig/network-scripts/ifcfg-ens33.200
DEVICE=ens33.200
BOOTPROTO=none
ONBOOT=yes
IPADDR=172.168.10.51
PREFIX=24
NETWORK=172.168.10.0
VLAN=yes # vim /etc/sysconfig/network-scripts/ifcfg-ens33.300
DEVICE=ens33.300
BOOTPROTO=none
ONBOOT=yes
IPADDR=172.168.20.51
PREFIX=24
NETWORK=172.168.20.0
VLAN=yesRestart the network service to apply the changes: # systemctl restart network After the restart, the VLAN interfaces retain their IP addresses and remain operational.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
