Vai al contenuto
Home » How to create VLAN in Linux using the ip command

How to create VLAN in Linux using the ip command

To create VLANs in SysLinuxOS and Debian GNU/Linux using the “ip” command, follow these steps:

1) Install the “vlan” package by running the following command:

sudo apt-get install vlan

2) Load the 8021q kernel module using the “modprobe” command:

sudo modprobe 8021q

Verify that the module is loaded by running:

lsmod | grep 8021q

The output should be similar to:

edmond@syslinuxos:~$ lsmod | grep 8021q
8021q 40960 0
garp 16384 1 8021q
mrp 20480 1 8021q

3) Create a VLAN subinterface for the desired network interface. For example, to create a VLAN subinterface for “eth0” with VLAN ID 10, run the command:

sudo ip link add link eth0 name eth0.10 type vlan id 10

4) Assign an IP address to the new VLAN subinterface using the “ip addr” command. For example, to assign the IP address 192.168.10.1/24 to the new VLAN subinterface, run the command:

sudo ip addr add 192.168.10.1/24 dev eth0.10

5) Activate the new VLAN subinterface using the “ip link” command:

sudo ip link set dev eth0.10 up

Repeat the previous steps to create additional VLAN subinterfaces if needed. To make the VLAN configuration persistent after reboot, add the following lines to the “/etc/network/interfaces” file:

sudo nano /etc/network/interfaces

Add:

auto eth0.10
iface eth0.10 inet static
address 192.168.10.1
netmask 255.255.255.0

Load the module permanently at boot:

sudo su -c 'echo "8021q" >> /etc/modules'

6) Restart the network service to apply the changes:

sudo systemctl restart networking.service

That’s it! You have created a VLAN subinterface in Linux using the “ip” command.

enjoy 😉

Lascia un commento

Il tuo indirizzo email non sarà pubblicato. I campi obbligatori sono contrassegnati *