I am trying to setup a CentOS with 3 NIC and static routes. eth0 has IP address and GW:, eth1 has IP address and GW:, eth2 has IP address and GW:

I want to accept traffic on eth1 from other machines (I have set eth1 of my server as gateway for those client machines) and send it over eth2 and further to router and vice-versa(reverse path).

Added route to system as

ip route add default via dev eth1  proto static  metric 1024

Now I am facing problem like traffic is receiving on eth1 but not going through eth2. It look like going through eth0.

I do not want to use NAT or IPTABLES for now, is it possible to route traffic of eth1 to eth2 and vice versa.

  • without natting, traffic sent from eth1 network to eth2 network will not find the correct return path, as i assume GW for machines on eth2 network is, so traffic will come via eth2 to a machine, and will get back via the GW as the source IP is on different subnet. to achive this i guess you need to perform natting or add routes on all the machines ! – MohyedeenN Nov 5 '14 at 14:27
  • @MohyedeenN Yes you are right it worked like that. – PrashantB Nov 6 '14 at 5:54

You can turn on IP forwarding with

echo 1 > /proc/sys/net/ipv4/ip_forwarding

But that's only half the truth. Not using NAT means, that all hosts need to know which router (gateway) is serving which network. As an example a machine in, say, wishes to connect with a machine in, say, using in one network & in the other. The machine needs this route

route add -net netmask gw

and the machine needs

route add -net netmask gw

Alternatively, you could use NAT & IPTables

echo 1 > /proc/sys/net/ipv4/ip_forward

iptables --flush

iptables -t nat --flush

iptables -t mangle --flush

iptables -A INPUT -i lo -j ACCEPT

iptables -A OUTPUT -o lo -j ACCEPT

iptables --policy INPUT ACCEPT

iptables --policy OUTPUT ACCEPT

iptables --policy FORWARD ACCEPT

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

This way you only have to configure (assuming routes are in place) the router.

  • I did routing setup as described and it worked for LAN only but not for internet traffic. – PrashantB Nov 6 '14 at 6:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.