Packet forwarding between interfaces

1.6k views Asked by At

I have a router with 2 interaces eth0 with IP 10.2.40.4 and eth2 with IP 10.2.20.3 I want the traffic from 10.2.40.0/24 network to egress out of 10.2.20.3 interface whose next hop IP is 10.2.20.1

I followed the below doc: https://unix.stackexchange.com/questions/186636/forward-packets-from-one-interface-to-another-interface-using-iptables

But was unable to get it through. Running a tcpdump on eth0, I can see traffic from 10.2.40.3(machine IP) to 8.8.8.8 and on eth2 I can see the traffic getting converted to 10.2.40.4 to 8.8.8.8

But the return traffic seems to be getting dropped.

1

There are 1 answers

6
Yigal Reiss On BEST ANSWER

N.B - edited the command (added eth2 as outgoing interface)

I understand from the setup described that the that the wan side on your router is eth2 which has address 10.2.20.3. Hence I would expect outgoing packets (on eth2) to have the source IP 10.2.20.3 and not 10.2.40.4. I think this indicates that you got your nat rules reversed or something.

In fact it seems that the only iptables rule that you need is: iptables -t nat -A POSTROUTING -o eth2 -j MASQUERADE

I suggest you remove all other DNAT/SNAT/MASQUERADE rules and try this one.