Wednesday, November 18, 2015

linux - How to redirect all traffic in eth0 to eth1 and back

I have a Ubuntu box with eth0 and eth1.


How can I redirect all the traffic coming from eth0 to eth1 and back?


Should I do DNAT and SNAT like below or just forwarding or both ?


Edit


My case is like this A-B-C, 3 machines. Both A & C in different network. B have two nic one is A's network (eth0) and other in B's network (eth1). I can't set B as the gateway in A nor B.


Below is how this was achieved by iptables on host B: SOLUTION


iptables -t nat -A PREROUTING -p tcp -m tcp ! --dport 22 -j DNAT --to-destination eth1IP
iptables -t nat -A POSTROUTING -p tcp -m tcp -o eth1 -j MASQUERADE

Have excluded port 22 so that SSH traffic is spared from the rules and my ssh to host C works.

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...