Operations 5 min read

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.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Configure Multiple VLANs and IP Addresses on a Single NIC in CentOS/RHEL

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 module

You can view module details with:

# modinfo 8021q

Create 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 300

Bring the new interfaces up:

# ip link set ens33.200 up
# ip link set ens33.300 up

Assign 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.300

At 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=yes

Create 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=yes

Restart the network service to apply the changes: # systemctl restart network After the restart, the VLAN interfaces retain their IP addresses and remain operational.

VLAN configuration result
VLAN configuration result
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxNetworkingipCentOSVLAN
Liangxu Linux
Written by

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.)

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.