Assume the following scenario, if I have a local machine (A) the requests another machine (B) using B's internal IP without regard the ports. But A and B are not on the same network, however, B has a public IP. what I want to do is when requesting machine B from machine A using B's internal IP, then some routing happens and translates B's internal IP to its public IP. How to achieve this functionality given the OS of the two machines is Ubuntu 14.04 ?


Solution 1:

Ok, after a small chat with Yahia Zakaria I managed to pinpoint the problem. The app uses more than TCP to communicate, so the proper DNAT should look:

iptables -t nat -A OUTPUT -d 192.168.1.15 -j DNAT --to-destination 54.3.22.1

And that's basically it.