Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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!

share|improve this question
    
I think I just failed my SAN roll reading this question... –  gWaldo Dec 10 '11 at 3:37
add comment

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.

share|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
add comment

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?

share|improve this answer
add comment

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.

share|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
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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