Draft
The “problem” is caused by dhcp server that overwrite our resolv.conf script and we lose this personalization during the IP release session. Not even is a good idea to replace the dns configuration proposed by the dhcp server, if it push that to you, probably there is a reason. But some time you want to use your own configuration such as when you use your broadband router and you want your /etc/resolv.conf has been preserved fron updates.
To prevent this nasty situation we can operate in two ways, determined by which dhcp client you are using: dhcpcd ord dhclient.
In the first case, dhcpcd (as in my Slackware laptop), prevent overriding can be obtained simply add the -R option to the dhcpcd command:
# dhcpcd -R eth0
In the second case, we must read the man page about dhclient-script which is invoked any time you use dhclient.
In:
man 8 dhclient-script
at the HOOKS section we can read:
HOOKS
When it starts, the client script first defines a shell function, make_resolv_conf , which is later used to create the /etc/resolv.conf file. To override the default behaviour, redefine this function in the enter hook script.
This means that we must to create /etc/dhclient-enter-hooks and redefine the make_resolv_conf function to satisfy our needs.
If we simply wants to prevent resolv.conf updates only, the fastest way is to redefine the function to do nothing:
# cat /etc/dhclient-enter-hooks make_resolv_conf() { exit 0 }
Then save the file and ensure it is executable:
# chmod a+x /etc/dhclient-enter-hooks
Note that, as explained in the man page, the dhclient-script is not standard so if this configuration doesn’t work, please read the man page.
Next: How to merge dns addresses pushed by the dhcp server and my own dns.
Thanks,
That’s works for my ubuntu 7.10.
In my case i create that function in /etc/dhcp3/dhclient-enter-hooks.d/dhclient-enter-hooks.
After that, /etc/resolv.conf isn’t override again.
Thanks for the tip, very helpful. However there’s a slight typo.
There is an extra ‘i’ that shouldn’t be present before make_resolv_conf in the dhclient-enter-hooks script, so it should contain:
make_resolv_conf() {
exit 0;
}
For completeness, some may like to make the file have execute permission too:
chmod a+x dhclient-enter-hooks
Thank you John for the typo and the tip. I updated the post.
Just found your page when googling for a way to keep the search-list in resolv.conf independent of the dhcp server.
For that, there is even a simpler solution, in /etc/dhcp3/dhclient.conf add:
supersede domain-name “lan internal some.domain”;
One quirk to beware of is that by calling ‘exit 0’ , the rest of the dhclient-script is aborted. A better example is:
make_resolv_conf() {}
I’m leaving this in case anyone else has to debug why dhclient-exit-hooks isn’t executing after someone has set their dhclient-enter-hooks to invoke ‘exit 0’.
Thank you so much ;)