You get a bonus - 1 coin for daily activity. Now you have 1 coin

CentOS/RedHat: configuring VLAN on network cards

Practice



Our task today is to set up receiving and sending traffic through network cards in CentOS and RedHat over VLAN (virtual private networks). In short - to configure VLANs on network interfaces.


In CentOS and RedHat there are 2 types of configuring (naming) VLAN interfaces:
  • vlanX : convenient in that it's configured once and is easier to move to a different physical interface (for example, specifying vlanX in a firewall is better than ethN.X - you won't need to change the interface name in a bunch of places)
  • ethN.X : convenient in that, when using it, traffic from the same VLAN can arrive on different network cards, which is impossible to organize with vlanX naming.

The naming choice is up to you. I'll describe both options. In our examples we'll be configuring VLAN 205 on the eth0 interface.


Note. You CANNOT use both naming schemes on the same server at the same time!



vlanX

If the situation allows - you can use vlanX naming.

So, we go to /etc/sysconfig/network-scripts and create the file ifcfg-vlan205.
$ cd /etc/sysconfig/network-scripts
$ sudo touch ifcfg-vlan205

Open this file for editing and enter the following data into it:
VLAN=yes
VLAN_NAME_TYPE=VLAN_PLUS_VID_NO_PAD
DEVICE=vlan205
PHYSDEV=eth0
BOOTPROTO=static
ONBOOT=yes
TYPE=Ethernet
IPADDR=192.168.1.1
NETMASK=255.255.255.0

Here:
  • DEVICE=vlan205 : here we specify the name of our interface: VLAN with number 205.
  • PHYSDEV=eth0 : here we specify exactly which physical interface should catch tagged traffic for VLAN 205.
  • IPADDR=192.168.1.1, NETMASK=255.255.255.0 - network details of the network interface

And restart the network subsystem:
$ sudo /etc/init.d/network restart



ethN.X

Sometimes you have to use ethN.X naming. The most common case is when tagged traffic with the same VLAN number arrives on different network cards.

We go to /etc/sysconfig/network-scripts and create the file ifcfg-eth0.205:
$ cd /etc/sysconfig/network-scripts
$ sudo touch ifcfg-eth0.205

Open it for editing and enter the following data:
VLAN=yes
DEVICE=eth0.205
BOOTPROTO=static
ONBOOT=yes
TYPE=Ethernet
IPADDR=192.168.1.1
NETMASK=255.255.255.0

By analogy with the previous case, here:
  • DEVICE=eth0.205 : interface name - eth0 with VLAN=205.
  • IPADDR=192.168.1.1, NETMASK=255.255.255.0 : network details of the virtual VLAN interface.

And restart the network subsystem:
$ sudo /etc/init.d/network restart


That's all there is to it.

Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Computer networks"

Terms: Computer networks