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 host2.serverAname.com. 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 host2.serverA.com).

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.


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    serverB.serverAname.com    host2    host2.serverAname.com

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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