Centos configure multiple gateways on single server

Temp

1
2
3
4
5
echo "1 admin" >> /etc/iproute2/rt_tables
ip route add $cidr dev $secondary_dev src $secondary_ip table admin
ip route add default via $secondary_gw dev $secondary_dev table admin
ip rule add from $secondary_ip/32 table admin
ip rule add to $secondary_ip/32 table admin

Persist (append admin table to rt_tables if it’s not already in there) on VLAN interface - works the same for additional NIC
/etc/sysconfig/network-scripts/ifcfg-eth0.100 (second interface)

1
2
3
4
5
6
DEVICE=eth0.100
ONBOOT=yes
BOOTPROTO=static
IPADDR=$ip
NETMASK=$nm
VLAN=yes

/etc/sysconfig/network-scripts/rule-eth0.100

1
2
from $cidr lookup admin
to $cidr lookup admin

/etc/sysconfig/network-scripts/route-eth0.100

1
2
$cidr dev eth0.100 table admin
default via $gw dev eth0.100 table admin