A common challenge I’ve come across is how to effectively using short hostnames and local domain servers in hosted solutions like Rackspace and Amazon Web Services.
For example, my local network has a domain like something.com, and 2 hosts like host1.something.com, and host2.something.com. I want to ssh or refer to my machine by their hostname, like
The easiest solution is to modify my /etc/resolv.conf and add the search domain to the top, like “search something.com”. The problem is that anytime I reboot that’ll get replaced by whatever is in default DHCP for Rackspace and AWS.
Another option is to start adding entries to /etc/hosts, but that becomes annoying to maintain across more than a couple of hosts.
In dealing with this challenge I found the proper way to deal with this (and other similar situations): the dhclient.conf file. Which is the DHCP client configuration file, see this man page
You can specify options and configurations in that file that will affect “volatile” files like the /etc/resolv.conf file.
The file can exist in different locations depending on the flavor of Linux:
I’ve found that on Cent, RedHat, and Amazon Linux the file lives, or needs to be placed, at /etc/dhclient.conf. On Debian, Ubuntu the file should reside at
For my original issue, using shortnames, I can specify the search like so:
supersede domain-name "something.com" ;
Then DHCP can change my /etc/resolv.conf all day long and my search domain will always show up.
Other common options/scenarios I’ve come across is using the localhost that’s running BIND as the primary nameserver which would be:
prepend domain-name-servers 127.0.0.1;
Or specifying a “failsafe” DNS server in case all are dead, like if you had your own DNS and wanted the final fall back to be something like Google’s DNS,
append domain-name-servers 22.214.171.124;