Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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

share|improve this question

closed as unclear what you're asking by Anthon, slm, Timo, Zelda, vonbrand Feb 27 '14 at 20:26

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question.If this question can be reworded to fit the rules in the help center, please edit the question.

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