2

Let me rephrase it.. I just need an IPtable rule to do double NAT-ting..

Host A - Host B - Host C - Host D

Host B should do both source NAT and destination NAT, so that my request from Host A reaches Host C and response from Host C reaches Host A.

In the same way, Host C should take care of requests from Host B to Host D and vice-versa.

So, basically, at end of the day, I want a request from Host A to Host D to happen, and a response from Host D to Host A to happen.

I am a little confused with where we need to use PREROUTING, POSTROUTING..

  • Would a web proxy be acceptable in your case ? It's more usual to do that this way. – lgeorget Feb 27 '14 at 14:53
  • I'm not able to test right now so I won't post this as an answer but I would try : iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE iptables -t nat -A PREROUTING -i eth0 -p tcp –dport 443 -j DNAT –to-destination 127.0.0.1:7777 iptables -A FORWARD -i eth0 -p tcp –dport 443 -j ACCEPT – lgeorget Feb 27 '14 at 14:56
  • possible duplicate of Double port forwarding - SSH – Kiwy Feb 27 '14 at 14:58
  • @Kiwy For me, it's a new question. It's entirely different to make a double port forwarding with SSH tunnels and making an iptables rule for a port redirection within a single host. – lgeorget Feb 27 '14 at 15:01
  • 2
    You write "Only HOST C can access HOST B". If only host C can access Host B as you are writing, how can ever forward a port from host A to host B as host A cannot access B. And if that all is not true, you should simplefy your question (and e.g. leave host A out of it completely – Anthon Feb 27 '14 at 16:01