Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

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

Two linux servers, server1 and server2, are on the same local network (they also have access to an external network).

Server2 has a local IP of and a host name of

QUESTION 1: If an application on server1 sends traffic to server2 using a host name of, what determines whether this traffic is routed to server2 using the local or external network?

QUESTION 2: To ensure that all traffic sent from server1 to server2 always uses the local network, could I simply include in the server1 /etc/hosts file the following?

...the thinking being, if the servers are always on the same network there should never be a need for server2 to send traffic to server1 via the external network (that I can think of anyway). Is this done in practice, or is some other method preferred?

share|improve this question
up vote 1 down vote accepted

Your question 2 is actually the correct answer, but doublecheck that you have:

hosts: files dns

in your /etc/nsswitch.conf

just to be sure.

generally external dns should be in your dns record, but in server1, files (which means /etc/hosts in this case) will take precedence and thus used to resolve the host to the internal ip, while the rest of internet will resolve the same hostname to the external ip.

the usual practice though is to use an internal domain altogether if you have to use dns name (mydomain.local for example).

share|improve this answer
The issue is the application uses one hostname for the server2 it resides in, even though it communicates with servers on both local and external networks. I can't change that. So the other local machine (e.g. server1) always receives traffic from, and so replies to the same host name, thereby going out to the external network when it doesn't need to. Question 2 is meant to have server1 resolve the hostname to a local IP address to keep traffic local. Sound OK? – gkdsp Mar 27 '12 at 17:26
I see. Yes, it sounds ok to me. – johnshen64 Mar 27 '12 at 17:28

As long as that host/DNS record is a private IP it will never route though the internet. You can view the routing table using route -n. The routing table will show you the path it takes to the destination network. If it the name resolved to an IP that was on another subnet (ie the internet) than it would route the traffic there accordingly

For your second question, if you add the 192.x.x.x HOSTNAME to the /etc/hosts file then it will always resolve to that. The DNS query would first look there, local cache, and if it's in neither then it will go thru name servers for resolution.

share|improve this answer
Thanks Ovi, makes sense. See my comment for johnshen64. The issue is the application uses a host name, not an IP address, to send out data. The application's server, server1, currently only has it's own IP addresses in its /etc/hosts file, as you might expect. So when server1 sends traffic to, it must be using the external IP address. My Question 2 attempts to keep this traffic local. – gkdsp Mar 27 '12 at 17:30
Add an entry to the /etc/hosts file on server1 for server2. You can add a line like this 192.X.X.X SERVER2.FQDN SERVER2.HOSTNAME – RomeNYRR Mar 27 '12 at 18:06
Thanks Ovi, I assume when you state 192.X.X.X I should replace those X's with the actual numbers, and SERVER2.HOSTNAME would be my above, right? If so, then would SERVER2.FQDN map to host2.FQDN? What does it do? – gkdsp Mar 27 '12 at 18:14
No problem. Replace the XXX's with the actual IP. The line should look like this: SERVER2 ... whenever server1 has packets it needs to send to server2 it will send it to that private IP when the name server2 is queried. Whatever name you have your application pointing to make sure it matches the hosts file – RomeNYRR Mar 27 '12 at 18:19
Got it, Thanks so much! – gkdsp Mar 27 '12 at 18:42

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.