You are here

Multiple NICs with Multiple Gateways on Centos

I have 2 NIC, eth0 has IP=192.168.0.34 and eth1 has IP=192.168.1.39

Here are my notes on add a 2nd NIC (eth1) with a new IP and different gateway from eth0

Default gateway will still be 192.168.0.33, meaning traffic originated from the machine will go out this interface, but traffic replies will go out the same interface that the request came in.


Set up eth0:
route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.0.32 0.0.0.0 255.255.255.240 U 0 0 0 eth0
169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
0.0.0.0 192.168.0.33 0.0.0.0 UG 0 0 0 eth0

ip route
ifconfig eth0

vi /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=none

HWADDR=00:21:9B:91:14:2E
IPADDR=192.168.0.34
NETMASK=255.255.255.240
GATEWAY=192.168.0.33
NETWORK=192.168.0.32
BROADCAST=192.168.0.47

ifup eth0

cat /etc/iproute2/rt_tables
echo "# dual nic-gateway below" >> /etc/iproute2/rt_tables
echo "10 eth0table" >> /etc/iproute2/rt_tables
cat /etc/iproute2/rt_tables

ip route add 192.168.0.32/28 dev eth0 src 192.168.0.34 table eth0table
ip route add default via 192.168.0.33 dev eth0 table eth0table

ip rule add from 192.168.0.34/32 table eth0table
ip rule add to 192.168.0.34 table eth0table

ip route flush cache

# Make it permanent
vi /etc/sysconfig/network-scripts/route-eth0
192.168.0.32 dev eth0 src 192.168.0.34 table eth0table
default via 192.168.0.33 dev eth0 table eth0table

vi /etc/sysconfig/network-scripts/rule-eth0
from 192.168.0.34/32 table eth0table
to 192.168.0.34 table eth0table

route -n
ip route
ifconfig eth0


Set up ETH1

route -n
ip route
ifconfig eth1

vi /etc/sysconfig/network-scripts/ifcfg-eth1

DEVICE=eth1
TYPE=Ethernet
ONBOOT=yes
BOOTPROTO=none

HWADDR=00:21:9B:91:14:30
IPADDR=192.168.1.39
NETMASK=255.255.255.224
GATEWAY=192.168.1.33
NETWORK=192.168.1.32
BROADCAST=192.168.1.63

ifup eth1

cat /etc/iproute2/rt_tables
echo "# dual nic-gateway below" >> /etc/iproute2/rt_tables
echo "11 eth1table" >> /etc/iproute2/rt_tables
cat /etc/iproute2/rt_tables

ip route add 192.168.1.32/27 dev eth1 src 192.168.1.39 table eth1table
ip route add default via 192.168.1.33 dev eth1 table eth1table

ip rule add from 192.168.1.39/32 table eth1table
ip rule add to 192.168.1.39 table eth1table

ip route flush cache

# Make it permanent
vi /etc/sysconfig/network-scripts/route-eth1
192.168.1.32 dev eth1 src 192.168.1.39 table eth1table
default via 192.168.1.33 dev eth1 table eth1table

vi /etc/sysconfig/network-scripts/rule-eth1
from 192.168.1.39/32 table eth1table
to 192.168.1.39 table eth1table

route -n
ip route
ifconfig eth1

Ref: www.howtoforge.com

User login