Monday, November 14, 2011

Routing in Dual Interface Linux Servers

If you have a two interface eth0 and eth1 in a Linux servers. Incoming traffic of eth0 send reply through eth1. Some times this may caused problem. Eg: mail-servers may receive mails through one interface and send through some other interface. There fore its a good practice to keep separate routing table for each interface in a Linux box. And send back the data through same interface it received.


Add two routing tables

Add routing tables on /etc/iproute2/rt_tables file

1 tble_eth1
2 tble_eth2


Incoming data as out put in same interface

Interfaces are 10.100.0.1 and 10.100.0.2 and gw is 10.100.0.254

ip route add 10.100.0.0/24 dev eth0 src 10.100.0.1 table tble_eth0
ip route add default 10.100.0.254 dev eth0 src 10.100.0.1 table tble_eth0
ip rule add from 10.100.0.1 table tble_eth0

ip route add 10.100.0.0/24 dev eth1 src 10.100.0.2 table tble_eth1
ip route add default via 10.100.0.254 dev eth1 src 10.100.0.2 table tble_eth1
ip rule add from 10.100.0.2 table tble_eth1

Run above script when interfaces getting up in a boot.

No comments:

Post a Comment