Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

I have two Linux CentOS servers setup in a local network. ServerA is and serverB is

There's an application on serverA that communicates with serverB using But, the traffic is blocked on serverB because the port being used has a firewall that only allows traffic on the local network to pass. Thus, serverB needs to see traffic from serverA as originating from (instead of

Is there a way I can configure the /etc/hosts file to ensure traffic always sent between the two servers uses local IP addresses, regardless of what hostname is in use, and for ALL applications?

If so, could someone walk me through an example? I only have 2 servers, so the simpler the better.

share|improve this question
up vote 2 down vote accepted

The "stupid" approach should work: add an entry in your /etc/hosts on serverA for every hostname (or combine into a single line - split here for legibility):    serverB    host2

Add any other hostnames for that IP as required. On serverB you really only need to have an IP for serverA if it's the one initiating connections, but it's a good idea anyway.

Also check that nothing strange is happening with your routing and default gateways, and triple-check with traceroute.

share|improve this answer
Thanks Andrew. Is your example /etc/hosts file above for serverA or B? Silly question -- if I'm editing the /etc/hosts file for serverB having local IP of, do all the local IP addresses need to be, or can I also include local IP addresses of If this is not how it's intended, how does traffic received at serverB from serverA know to send traffic back to serverA on – gkdsp Mar 27 '12 at 2:32
@gkdsp Updated - that's for serverA. The connection (presumably TCP) has a source IP and port; serverB shouldn't need to know how to resolve serverA to reply, but it doesn't hurt. – Andrew Mar 27 '12 at 2:51

If I understand you well, you need to be able to connect to the same server from different locations with different destination IPs.

One way to do this is to use Split DNS. This actually includes defining two separate zone files for the same domain. One internal view to be viewed by internal users (private IPs) and other external view to be viewed by external users (public IPs). Have a look at this page and this on configuring multiple views in bind DNS server.

share|improve this answer

Your Answer


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.