How to set up two default routes in linux (corresponding to two interfaces), such that incoming traffic from both interfaces is accepted.
I have a host having two NICs
eth1. Its connected to two networks, say:
(Both networks are connected to the internet.)
The routes are (
ip route show):
default via 22.214.171.124 dev eth0 metric 1 default via 126.96.36.199 dev eth1 metric 2 188.8.131.52/24 dev eth0 src 184.108.40.206 220.127.116.11/24 dev eth1 src 18.104.22.168
(Lower metric means higher priority.)
Now when someone pings
22.214.171.124 from some external host (say
126.96.36.199), there is no reply.
The output of
tcpdump -i eth1 on my host is:
22:41:27.431539 IP 188.8.131.52 > 184.108.40.206: ICMP echo request, id 8625, seq 4, length 64 22:41:28.439492 IP 220.127.116.11 > 18.104.22.168: ICMP echo request, id 8625, seq 5, length 64 22:41:29.447666 IP 22.214.171.124 > 126.96.36.199: ICMP echo request, id 8625, seq 6, length 64 22:41:30.455528 IP 188.8.131.52 > 184.108.40.206: ICMP echo request, id 8625, seq 7, length 64
After some research, it turns out that when linux network stack receives a packet from
220.127.116.11, it checks its routing table to see what interface should have been used for
18.104.22.168 (which is
eth0 in the routing table). Now, since the packet came from
eth1 interface, linux simply discards it (This policy is probably to prevent IP spoofing).
What I want is is:
Outgoing traffic (locally originated) should use
eth0interface by default.
Incoming traffic should be accepted from both interfaces. (So
22.214.171.124should be able to ping both