09.05.08

Keep DHCP From Overwriting Search Domains

Posted in Intermediate, Linux at 3:11 pm by Techie

Let’s say you have a bunch of hosts on example.com, such as mercury.example.com, venus.example.com, and jupiter.outerplanets.example.com. You spend a bunch of your time on the command line, so you want to be able to access them with just the short host name, i.e., you want to be able to just type ssh mercury and not worry about the domain.

If you happen to be on the same domain, e.g. on saturn.example.com, this usually works fine. What if you’re not? The usual answer is to edit your /etc/resolv.conf file, and edit your search domains like so:

search example.com outerplanets.example.com

This works great — you can even ssh jupiter and it’ll do the right thing. It will, that is, right until you DHCP up a new IP address, say on another Internet connection. Then it overwrites your search domains, and you have to re-edit the file. What’s a techie to do? Use dhclient.conf, of course!

On hardy, I edited the file /etc/dhcp3/dhclient.conf and added this line:

supersede domain-name "example.com outerplanets.example.com";

Then, I did an sudo /etc/init.d/dhcdbd force-reload to make the dhclient change. However, my connection still had the old network information. To fix that, I just stopped and started my connection like so:

sudo ifconfig eth0 down
sudo ifconfig eth0 up

Voila — my search domains work again, and will work the next time I DHCP up a new IP.

Leave a Comment

Bad Behavior has blocked 280 access attempts in the last 7 days.