VLAN (Virtual Local Area Network) interfaces are a way to allow multiple networks to co-exist in a single physical interface. This is done by creating a virtual interface under Linux that tags the packet with the correct network information. This switch that the server connects to can then determine what network the packet is going to based on the tag in the header of the packets. This feature does require a “managed” switch. Old hubs and unmanaged switches can not handle VLANs so make sure your switches are capable of this feature.
The Linux kernel you are using must have 802.1q built into the kernel or available as a module. Most modern distributions do. My system has the 802.1q available as a module so that is what I will document.
Loading the Module
Edit /etc/modprobe and add in the module. I added the following line in right after the line that loads my NIC (eth0).
alias vlan 8021q
Creating the Interface Startup
In my example, I will be using VLAN ID 20. Change the 20 to what ever your VLAN will be. Make a copy of your current network startup file for the new vlan interface.
# cp /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/sysconfig/network-scripts/ifcfg-eth0.20
Edit the new file and change the following lines.If the example below, make sure you assign your correct IP address information and the HWADDR should be the same as your one in the ifcfg-eth0 file.
# vi /etc/sysconfig/network-scripts/ifcfg-eth0.20 DEVICE=eth0.20 BOOTPROTO=static DHCPCLASS= HWADDR=00:11:11:19:7D:92 ONBOOT=yes TYPE=Ethernet IPADDR=192.168.200.1 NETMASK=255.255.255.0 BROADCAST=192.168.200.255NETWORK=192.168.200.0 NOZEROCONF=yes VLAN=yes
Restart the network and make sure the VLAN comes up OK.
# /etc/init.d/network restart