trying to understand how Linux /etc/hosts file works with local and external IP addresses
- by gkdsp
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)?