Linux – Tag VLANs and add IP addresses to Linux server

iplinuxlinux-networkingnetworkingvlan

I've been told to tag VLANs and add IP addresses to a Linux server.
It's using /etc/sysconfig/network-scripts/.

I've never tried this before.

There's multiple VLANs with different IP subnets, some VLANs has the same IP subnets announced.

The physical server has 2 ethernet in port 2 and 3, and both ethernet contains same VLANs.

My approach would be to add ifcfg-eth1.101 for my first IP address with the following inside, for VLAN 101:

DEVICE=eth1.101
BOOTPROTO=static
ONBOOT=yes
IPADDR=23.543.11.10
NETMASK=255.255.255.255
USERCTL=no
NETWORK=23.543.11.1
VLAN=yes

… then run ifup eth1.101 and systemctl restart network.service

Is this correct, and am I missing something?

Best Answer

Looks correct to me, for any RedHat-like distribution that is not using NetworkManager.

If you have two NICs with same VLANs, you might want to first bond the ports together (i.e. bond eth1 and eth2 into bond0) and then hang the VLANs onto the bond (i.e. instead of ifcfg-eth1.101 with DEVICE=eth1.101 you would use ifcfg-bond0.101 with DEVICE=bond0.101 etc.)

When using bonding, remember to select BONDING_OPTS="mode=active-backup" bonding mode unless you have confirmed with your network administrators that the default balance-rr bonding mode (or any other bonding mode) can be used. With managed switches, balance-rr may cause "MAC address flapping" warnings in switches and/or routers, which may annoy the network admins. If MAC address hijacking protection is enabled on the switches, the use of balance-rr may look like a hijacking attempt and cause a false alarm.

If you need multiple IP addresses on top of a VLAN, the syntax for extra IPs is (for a bonded interface) filename ifcfg-bond0.101 for the "main interface", ifcfg-bond0.101:0 for the first extra IP address, and so on. The number after the full stop is the VLAN number, and the number after the colon is the index number for extra IPs.

The contents of the ifcfg-bond0.101:0 file should be similar to when configuring just one IP address:

DEVICE=eth0.101:0
BOOTPROTO=static
IPADDR=xx.xx.xx.xx
NETMASK=255.255.255.0
ONBOOT=yes
VLAN=yes

Note that configuring IP aliases on top of VLANs in this way is guaranteed to be supported only on RHEL/CentOS 5 and above; it may have been added in mid-4.x release cycle, but I'm not sure about that.

With older OS versions, you would have had to write a custom script to initialize the IP aliases manually with ifconfig, as the initscripts package in 4.x did not originally have the capability to handle such a combination.

Related Topic