Configuring VLAN interfaces in Linux

In this post, we will see how to configure VLAN tagged interfaces on a Linux machine. This will allow you to connect your machine to different VLANs in your network using a single interface. In this example, am going to configure the VLAN tagging on the network card interface directly. If you want reduntancy in the network level, it is recommended to configure bonding and then configure VLAN taggging on that bonded interface. Based on the bonding parameter configured, you can make the bond work in active-standby mode / link aggregation / active-active or so…

In this example, am having an interface eth0 configured with IP 192.168.0.1. Now, i need to configure 2 VLAN tagged interfaces for VLAN 10 & 20. The VLAN 10 interface should be assigned an IP 192.168.10.1 & VLAN 20 with IP 192.168.20.1. The interface configuration file is as follows:


#more /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
ONBOOT=yes
BOOTPROTO=none
NETMASK=255.255.255.0
IPADDR=192.168.0.1
USERCTL=no
PEERDNS=yes
TYPE=Ethernet
IPV6INIT=no

Creating VLAN 10 tagged interface:

To configure a VLAN tagged interface with VLAN_ID 10, copy the ifcfg-eth0 file and make ifcfg-eth0.10 first.

# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0.10

 

Now edit the contents as follows. Dont forget to add the entry VLAN=yes in the VLAN tagged interface configuration file.


#more /etc/sysconfig/network-scripts/ifcfg-eth0.10
DEVICE=eth0.10
ONBOOT=yes
VLAN=yes
BOOTPROTO=none
NETMASK=255.255.255.0
IPADDR=192.168.10.1
USERCTL=no
PEERDNS=yes
TYPE=Ethernet
IPV6INIT=no

Creating VLAN 20 Tagged interface:

Copy the VLAN 10 interface configuration file to VLAN 20 interface configuration file.


#cp /etc/sysconfig/network-scripts/ifcfg-eth0.10 /etc/sysconfig/network-scripts/ifcfg-eth0.20

Edit the ifcfg-eth0.20 file and should look the following:

#more /etc/sysconfig/network-scripts/ifcfg-eth0.20
DEVICE=eth0.20
ONBOOT=yes
VLAN=yes
BOOTPROTO=none
NETMASK=255.255.255.0
IPADDR=192.168.20.1
USERCTL=no
PEERDNS=yes
TYPE=Ethernet
IPV6INIT=no

Restart the network service now

#service network restart

Switch Level Configuration:

For the VLAN interfaces to communicate through the switch, the switch port to which we connect the server interface should be configured as a trunk port. This is to be done in the network switch level. The interface fastethernet 0/2 here represents the interface in the swithc to which the server is connected. You may have to replace the interface type and numbers according to your physical connectivity.

Switch#(config)interface fastethernet 0/2
Switch#(config-if)no switchport mode access
Switch#(config-if)switchport mode trunk
Switch#(config-if)switchport trunk allowed vlan 0,10,20

Configuring VLAN tagged interfaces using vconfig command

We can configure VLAN interfaces using vconfig command also. This configuration is a temporary one and will be lost after a reboot.

To add a VLAN 10 tagged interface, use the following command:

#vconfig add eth0 10

Use ifconfig to assign IP address to vlan interface :

# ifconfig eth0.10 192.168.10.1 netmask 255.255.255.0 broadcast 192.168.1.255 up

Get detailed information about VLAN interface:

# cat /proc/net/vlan/eth0.5

Get the VLAN interface information on the server

#cat /proc/net/vlan/config

If you wish to delete VLAN interface delete command

# ifconfig eth0.5 down
# vconfig rem eth0.5


source: https://sysadmincorner.wordpress.com/2012/04/06/configuring-vlan-interfaces-in-linux/#more-41
Attachments
There are no attachments for this article.
Related Articles RSS Feed
RHEL: Crash kernel dumps configuration and analysis on RHEL 7
Viewed 1093 times since Sat, Jun 2, 2018
Use Fail2ban to Secure Your Server
Viewed 1482 times since Fri, Jul 5, 2019
linux ssh How to Hide the OpenSSH Version Details when Telnet to Port 22
Viewed 138 times since Wed, Apr 22, 2020
Stunnel Setup
Viewed 3102 times since Fri, Sep 28, 2018
How to find the largest files and directories in Linux?
Viewed 1022 times since Sun, May 20, 2018
PROCESSOR AND MEMORY INFORMATION
Viewed 753 times since Sat, Jun 2, 2018
Fałszujemy rozpoznania skanerów #1
Viewed 1001 times since Mon, May 21, 2018
Easily Monitor CPU Utilization in Linux Terminal With Stress Terminal UI
Viewed 613 times since Thu, Apr 18, 2019
List usernames instead of uids with the ps command for long usernames
Viewed 470 times since Wed, Jul 25, 2018
Top 4 Reasons for Node Reboot or Node Eviction in Real Application Cluster (RAC) Environment
Viewed 7465 times since Thu, Jun 21, 2018