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
andeth2
intobond0
) and then hang the VLANs onto the bond (i.e. instead ofifcfg-eth1.101
withDEVICE=eth1.101
you would useifcfg-bond0.101
withDEVICE=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 defaultbalance-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 ofbalance-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: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 theinitscripts
package in 4.x did not originally have the capability to handle such a combination.