How to Assign Multiple VLAN IPs on a Single Linux NIC (CentOS/RHEL)
This guide explains how to configure multiple VLAN‑tagged interfaces on a single Linux network card in CentOS/RHEL, covering kernel module loading, creating VLAN interfaces with ip, assigning IP addresses, and persisting the settings via ifcfg files so they survive reboots.
In some scenarios you may need to assign IP addresses from different VLANs to the same physical network interface on a Linux server (CentOS/RHEL). This requires the switch port to be configured as a trunk with the desired VLANs added.
Example setup
Assume a server with two Ethernet cards: ens33 for data traffic and ens38 for control/management. The data NIC will carry two VLANs:
VLAN ID 200 – network 172.168.10.0/24
VLAN ID 300 – network 172.168.20.0/24
Load the 8021q kernel module
# lsmod | grep -i 8021q # no output means the module is not loaded
# modprobe --first-time 8021q
# lsmod | grep -i 8021q
8021q 33080 0Verify module information:
# modinfo 8021qCreate VLAN interfaces
Use the ip command to add VLAN sub‑interfaces to ens33:
# 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
# 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 interfaces have IPs, but the configuration is not persistent across reboots.
Make the configuration permanent
Edit the main interface file /etc/sysconfig/network-scripts/ifcfg-ens33 (if it does not exist, create it) with at least the following content:
TYPE=Ethernet
BOOTPROTO=none
DEVICE=ens33
ONBOOT=yesCreate separate 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 networkAfter the restart, the VLAN interfaces retain their IP addresses and remain up.
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.
