Friday, November 18, 2016

Is a matching entry in /etc/hosts required for hostname?



I was installing a Tomcat webapp that refused to work until I stumbled on someone else's issue with an unrelated product. The solution was to add the machine's name to /etc/hosts, to match the name returned by hostname. Is this required for general Linux networking to function correctly?



My webapp is running in a virtual machine so that I can test the webapp, and I don't normally bother with the /etc/hosts file on VMs. I just shook my fist and cursed Tomcat and webapp's behavior. I read /etc/hosts , /etc/sysconfig/network and hostname?, but that doesn't say if it's required or not.


Answer




If DNS won’t resolve a system’s hostname to an IP, things may break, depending on how they’re configured — unless you manually add an entry to /etc/hosts. This seems to be one of those occasions. The reverse can also apply in some situations, too.



It’s generally considered good practice to add such an entry to /etc/hosts — in fact, most Unixish operating systems tend to do this for you as part of their initial configuration (or, if you’re using DHCP, when they obtain a lease).


No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...