I have two servers A and B.

Server A has a private ip 10.0.0.4 and a public ip of 1.2.3.4 Server B has a private ip 10.0.0.5 and a public ip of 5.6.7.8

running ifconfig on Server A says eth0 has inet addr: 10.0.0.4

running ifconfig on Server B says eth0 has inet addr: 10.0.0.5

Servers A and B are on the same network, and when Server A talks to Server B, they talk using their private IPs. I would like to, however, have them communicate using their public IPs. I believe this involves some NAT trickery with iptables.

How can I get Server A to communicate with Server B through their public IPs and not the private IPs? Do I need to have in place a SNAT and DNAT rule? I realize I am a noob, so any advice is helpful.

The motivation for this is that I'm trying to set up a VPN connection where there are conflicting IPs on either network- thus I need to NAT my private IP to something else.

Thanks!

link|improve this question

0% accept rate
I think I just failed my SAN roll reading this question... – gWaldo Dec 10 '11 at 3:37
feedback

4 Answers

Unless both devices are directly connected to the internet, they do not have public IP addresses. If both devices are connected to the internet via a router/gateway the gateway does the NAT translation for both devices, so both devices share a single public IP address.

link|improve this answer
But what if the gateway has more than one public IP that it can NAT for? – Bill Weiss Dec 10 '11 at 16:21
Sounds like that would have been valuable information to add to the question. – Tim Dec 10 '11 at 17:46
He says there are two public IPs, right? – Bill Weiss Dec 11 '11 at 7:04
feedback

You could put put your servers in different subnets; that way, even though they are physically linked, they should not communicate via their private interfaces since the routing tables will route their packets via a gateway, which currently isn't the case.

Could you maybe describe your topology in a little more detail? How are the routing entries for both servers? Do they share a gateway to connect to the internet or do they both in fact have public (as in internet-visible) IP addresses?

link|improve this answer
feedback

Without further information about the topology it is hard to give a definite answer.

If both devices have two interfaces (one for public ip and one for private ip) then one would want to probably create a vlan (I'm not a network expert either, but if segmentation is the goal for vpn then a vlan seem appropriate) for each private interface to isolate the networks.

link|improve this answer
My servers are located in the cloud using Amazon's Virtual private cloud, and they are located in the same subnet. They both have static IPs associated with them. I've read that you can use AWS NAT instances (which I have one spun up) to do this, and you can read about them here docs.amazonwebservices.com/AmazonVPC/latest/UserGuide/…. This guide however, fails to explain how to do the actual NAT! – Tucker Dec 10 '11 at 16:50
feedback

As long as the public IPs are actually on the machines in question, you can add host routes to force direct communication using the public IPs.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.