trying to understand how Linux /etc/hosts file works with local and external IP addresses

Posted by gkdsp on Server Fault See other posts from Server Fault or by gkdsp
Published on 2012-03-27T15:38:47Z Indexed on 2012/03/27 17:33 UTC
Read the original article Hit count: 279

Filed under:

Let's say I have a Linux server with an external IP of 123.456.789.012 and a local IP of 192.168.0.1. If it's /etc/hosts file looks like, for example,

123.456.789.012 host2.mydomain.com
192.168.0.1 host2.mydomain.com

When an application on the server generates traffic to send using host2.mydomain.com, how does the server know whether to use the local or external IP address (since the same host name shows two IP addresses)?

Or, does it need something additional than what I've presented here to decide this?

Or, does it just sent it out as host2.mydomain.com and let the receiving end deal with it (if so, how to make sure traffic intended for local network indeed goes to local network)?

© Server Fault or respective owner

Related posts about linux