Thursday, April 26, 2012

Patching /etc/resolv.conf file in VMs

I use a Linux VM for my development. I run my VM using VMWare Player. The VM obtains the IP address using a DHCP client run by NetworkManager (it is a part of vmware-tools suite). Every time the VMWare Player issues a new IP address, my /etc/resolv.conf file gets overwritten and I am left with only "localhost" as the search domain.

Some of the machines that I connect to require fully qualified names to resolve. For e.g. I cannot look up host1, instead I should look up host1.corpdomain.com. Hence I should make sure that the /etc/resolv.conf has the correct search directive after every DHCP lease.

The NetworkManager first copies the /etc/dhcp/dhclient.conf file under /var/run/nm-dhclient-eth0.conf and then adds a few extra directives of its own. So all that I had to do to fix the issue is to add the following two lines at the end of /etc/dhcp/dhclient.conf file:

prepend domain-search "corpdomain.com";
prepend dhcp6.domain-search "corpdomain.com";

Please make sure you don't miss the double-quotes and the semi-colon. Otherwise it will silently fail without giving any error. After adding this just restart your VM. Everything should work fine.

No comments: