1

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

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 192.168.10.3 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.

2
  • 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 192.168.10.1, so traffic will come via eth2 to a machine, and will get back via the GW 192.168.10.1 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
    Commented Nov 5, 2014 at 14:27
  • @MohyedeenN Yes you are right it worked like that.
    – PrashantB
    Commented Nov 6, 2014 at 5:54

1 Answer 1

2

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 192.168.10.0/24, say 192.168.10.25, wishes to connect with a machine in 192.168.20.0/24, say 192.168.20.25, using 192.168.10.3 in one network & 192.168.20.2 in the other. The machine 192.168.10.25 needs this route

route add -net 192.168.20.0 netmask 255.255.255.0 gw 192.168.10.3

and the machine 192.168.20.25 needs

route add -net 192.168.10.0 netmask 255.255.255.0 gw 192.168.20.2

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .