Operations 5 min read

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.

Liangxu Linux
Liangxu Linux
Liangxu Linux
How to Assign Multiple VLAN IPs on a Single Linux NIC (CentOS/RHEL)

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  0

Verify module information:

# modinfo 8021q

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

Bring the new interfaces up:

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

Assign IP addresses

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

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

Restart the network service to apply the changes:

# systemctl restart network

After the restart, the VLAN interfaces retain their IP addresses and remain up.

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.