Connecting servers to VLAN

Configuring VLAN (Virtual Local Area Network) on Linux servers allows you to create virtual networks to control and isolate traffic on the network.

Ubuntu 22.04

Configuring VLANs on two Ubuntu 22.04 servers can be done using the netplan tool, which provides a convenient way to configure network interfaces in Ubuntu.

1. Untagged VLAN configuration

Let's configure a VLAN without using identifiers (VLAN ID), but in this case it will be called an "untagged" VLAN. Untagged VLAN means that traffic on this VLAN will be transmitted without a VLAN tag through the physical interface.

Let's find out the interface for configuring VLAN using the ip link show command.

In this case, on both servers we have it enp0s8.

2. Assign VLAN IP-addresses

Let's find our netplan configuration; the YAML file can be called differently.

Let's open the configuration and make changes to assign an IP address to our interface.

sudo nano /etc/netplan/*.yaml

You need to make changes on both servers.

enp0s8:
dhcp4: no
addresses: [192.168.1.2/24, ]
gateway4: 192.168.1.1

Be careful with syntax.

After that we apply the settings:

sudo netplan apply

Let’s also check whether the address has been assigned on the interface:

3. Ping addresses on the local network

Now the servers are connected to each other using VLAN.

4. Install the VLAN package

First of all, make sure that the vlan package is installed on both servers. You can install it using the command:

sudo apt update
sudo apt install vlan

5. Also add 2 tags to our interface

All network packets will be tagged before being sent through this interface. For example, let's add two VLAN identifiers 10 and 20 to our netplan configuration; all network packets will be marked before being sent through this interface.

Open netplan and add vlan parameters:

vlans:
vlan10:
id: 10
link: enp0s8
addresses: [192.168.1.2/24]

vlan20:
link: enp0s8
id: 20
addresses: [192.168.1.2/24]

Be careful with the syntax as YAML is unforgiving.

Same for the second server:
vlans:
vlan10:
id: 10
link: enp0s8
addresses: [192.168.1.1/24]


vlan20:
link: enp0s8
id: 20
addresses: [192.168.1.1/24]

After that, apply the settings: sudo netplan apply

6. Let’s check if everything is configured correctly

After applying the configuration, verify that the VLAN is working correctly by running the ip a command to view the current network configuration on the server.

Debian 11

Configuring VLANs on two Debian servers can be done using the /etc/network/interfaces file, which provides a convenient way to configure network interfaces on Debian.

1. Untagged VLAN configuration

Let's configure a VLAN without using identifiers (VLAN ID), but in this case it will be called an "untagged" VLAN. Untagged VLAN means that traffic on this VLAN will be transmitted without a VLAN tag through the physical interface.

First, we find out the interface for configuring VLAN using the ip link show command.

In this case, on both servers we have interface enp0s8.

2. Assign an IP address to our interface

ip addr add 192.168.1.1/24 dev enp0s8
ip addr add 192.168.1.2/24 dev enp0s8

We’ll also add this to /etc/network/interfaces

auto enp0s8
Iface enp0s8 inet static
address 192.168.1.1
netmask 255.255.255.0

Similarly for second server:

Let's reboot the server:

As you can see the address is registered
Command to check: ip addr

After a reboot, we check whether the servers ping each other:

3. Set up a tagged VLAN

All network packets will be tagged before being sent through this interface. For example, let's add VLAN identifier 10 to our configuration; all network packets will be marked before being sent through this interface.

Here enp0s8.10 is the virtual interface for VLAN ID 10 and it is configured to use the physical interface enp0s8.

Similar for second server:

Ip addr 192.168.1.1/24 dev enp0s8.10
Ip addr 192.168.1.2/24 dev enp0s8.10

We will also write it in the /etc/network/interfaces config so that our settings are saved after a reboot.

Similar for second server:

auto enp0s8.10
Iface enp0s8.10 inet static
address 192.168.1.1
netmask 255.255.255.0

4. Check the vlan configurations

Enter the command: ip addr

CentOS 7

VLAN configuration on two CentOS servers can be done using network interface configuration files.

1. Untagged VLAN configuration

Let's configure a VLAN without using identifiers (VLAN ID), but in this case it will be called an "untagged" VLAN. Untagged VLAN means that traffic on this VLAN will be transmitted without a VLAN tag through the physical interface.

Find out the interface for configuring VLAN using the ip addr command.

In this case, on both servers we have it enp0s8.

2. Assign an IP address to our interface

Open the network interfaces configuration file for editing:

sudo nano /etc/sysconfig/network-scripts/ifcfg-enp0s8

In this case, it is called similarly to the interface.

ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
VLAN=no
IPADDR=192.168.1.1
NETMASK=255.255.255.0

3. Restart the network service

sudo systemctl restart network

4. Check whether the address has been added to the interface and ping another server

ip addr

Let's ping the servers.

The servers are accessible to each other.

5. Configuring tagged VLAN

Open the network interfaces configuration file for editing using the physical interface (in this case enp0s8):

sudo nano /etc/sysconfig/network-scripts/ifcfg-enp0s8

Let's add the following lines to the file:

VLAN=yes
VLAN_ID=10

Also add the VLAN identifier to the line DEVICE=enp0s8

DEVICE=enp0s8.10

6. Restart the network service on both servers

sudo systemctl restart network

7. Check if the tag has been added to the interface and ping another server

ip addr

Both servers have a connection to each other.

Tagged VLAN is configured.