To make use of a trunk interface connected to our linux box with a single interface we can configure subinterfaces accessing specific VLAN segments, here we will use Debian and RHEL, assigning two subinterfaces, to each, on will use DHCP to get an IP in the specific subnet, we configure a static address on the other one.
Debian, Ubuntu
Interface |
VLAN |
subnet |
IP |
ens18 |
1 (native, untagged) |
192.168.0.0/24 |
192.168.0.8 |
ens18.100 |
100 |
10.0.0.0/24 |
10.0.0.2 |
ens18.101 |
101 |
10.0.1.0/24 |
10.0.1.5 |
First we install the vlan package with
apt install vlan
Now we edit the /etc/network/interfaces config file. Opening it we see that our existing interface is called ens18. So to add the subinterfaces we append the following:
… Create a subinterface on VLAN100, using DHCP auto ens18.100 iface ens18.100 inet dhcp Create a subinterface on VLAN101, assigning static IP auto ens18.101 iface ens18.101 inet dhcp address 10.0.1.5/24 …
After a reboot we check if the interfaces are active:
RHEL, CentOS
Interface |
VLAN |
subnet |
IP |
ens18 |
1 (native, untagged) |
192.168.0.0/24 |
192.168.0.9 |
ens18.100 |
100 |
10.0.0.0/24 |
10.0.0.3 |
ens18.101 |
101 |
10.0.1.0/24 |
10.0.1.6 |
In RHEL and CentOS 7 and 8 the vlan module (called 8021q) should be loaded by default, we can verify it:
modinfo 8021q
If it is loaded, we proceed by listing the available network interface in the system.
ls -l /etc/sysconfig/network-scripts
In our example we have ens18 just like the Debian box had
We simply create the corresponding configuration files for both subinterfaces:
vi /etc/sysconfig/network-scripts/ifcfg-ens18.100
DEVICE=ens18.100 BOOTPROTO=dhcp ONBOOT=yes VLAN=yes
vi /etc/sysconfig/network-scripts/ifcfg-ens18.101
DEVICE=ens18.101 BOOTPROTO=none ONBOOT=yes IPADDR=10.0.1.6 PREFIX=24 NETWORK=10.0.1.0 VLAN=yes
Comments