resolv.conf is being modified, and not by me (a DHCP problem)
This problem occurred because DHCP overwrites the contents of resolv.conf. and I didn’t know that. But you have quite a bit of control over what DHCP puts into that file. Details are below.29 July 1998
After my reboot as a result of my floppy disk mount exploits, I found that the contents of resolv.conf had been modified.What is dhcp?
DHCP (Dynamic Host Configuration Protocol ) is defined in RFCs 2131 and 2132 and provides a client with a complete set of TCP/IP configuration values. In short, it allows a client to obtain, among other things, an IP number, the name of the domain, and a list of name servers.I recommend you read the following book: TCP/IP Network Administration by Craig Hunt and published by O’Reilly, ISBN 1-56592-322-7. This book is also known as the crab book (you’ll know why when you see the cover).
The problem
As mentioned above, I noticed a minor but very irritating problem. Whenever the name was rebooted, the contents of resolv.conf would change and manual modification was needed in order for the system to resolve names again.What appeared after a reboot:
search myisp.com nameserver 11.22.33.44 nameserver 11.22.33.45
What I wanted:
domain www.example.org nameserver 10.0.0.1 # my min-dns server nameserver 11.22.33.44 nameserver 11.22.33.45
31 July 1998
It turns out that DHCP client will rewrite the contents of resolv.conf with the information it obtains from the DHCP server. Well, that’s not good enough.Here’s what resolv.conf contains after a reboot:
search myisp.com nameserver 11.22.33.44 nameserver 11.22.33.45
Here’s what I want it to contain:
domain www.example.org nameserver 10.0.0.10 # my min-dns server nameserver 11.22.33.44 nameserver 11.22.33.45
I’ll report back after I get this solved. The reason I want the above is related to my name server.
1 August 1998
White rabbits.The message from the mailing list mentions the prepend command and to check out man dhclient.conf. What I find there is I need to do something like:
prepend { domain-name "www.example.org"; domain-name-servers 10.0.1.4; }
I tried that. Then did the following to restart dhclient:
bash# cat /var/run/dhclient.pid 5676 bash# kill -9 5676 bash# dhclient ed0
The prepend command I used gave syntax errors. And my ed1 link died. So I issued:
ifconfig ed1 inet 10.0.0.1 255.255.255.0
After several attempts. No luck.
prepend domain-name "www.example.org";
Neah. Still doesn’t work.
Checking the documentation….
The example provided by man dhclient.conf shows the prepend statement within the interface "ep0" {...} statement. I found this didn’t work for me and no effect on the contents of /etc/resolv.conf. My next attempt involved moving the prepend command to be above the interface command.Ahuh!
Now I’m getting the following /etc/resolv.conf file:
search www.example.orgmyisp.com nameserver 10.0.0.1 nameserver 11.22.33.44 nameserver 11.22.33.45
For some reason the domain-name request is being prepended to the search statement. Very weird. I’d like to remove the request statement altogether. There is something in the manual about that. I’ll check that again….
I tried removing the domain-name option from the interface statement. That seemed to have nil effect.
I’m lost. I found nothing in the mailing list archives. And http://www.dejan.com had nothing either. I’ll ask the mailing list again.
8 August 1998
It has been recommended that I try the following command (note the extra space in the quoted string):prepend domain-name "www.example.org "
After restarting dhclient, /etc/resolv.conf contains the following:
search www.example.org myisp.com nameserver 10.0.0.1 nameserver 11.22.33.44 nameserver 11.22.33.45
Note: I still need to do the following to get ed1 running after restarting dhclient:
ifconfig ed1 inet 10.0.0.1 255.255.255.0
So the next thing I try doing is the supersede command:
supersede domain-name "www.example.org "
OK! That gives me:
search www.example.org nameserver 10.0.0.1 nameserver 11.22.33.44 nameserver 11.22.33.45
This works. The names resolve nicely. I don’t have to manually change /etc/resolv.conf after a reboot.
Now, how to swap domain for search in the above? Do I want to?
dhclient.conf (added on 16 October 1998)
A recent email prompted me to add my /etc/dhclient.conf file to the website. It might help./etc/dhclient-enter-hooks (added on 20 November 2002)
See also http://www.netbsd.org/Documentation/network/dhcp.html#keep_resolv_conf which recommends this file:
# cat /etc/dhclient-enter-hooks
make_resolv_conf() {
echo "doing nothing to resolv.conf"
}
See dhclient-script(8) for details.
I had the same issue with redhat 7.1 and all I had to do is add the line
PEERDNS="no"
to the file
/etc/sysconfig/network-scripts/ifcfg-eth1
Mike
I recall this on Mandrake 8.0. Since I’m not terribly clever and didn’t find that option, I ended up plonking a big "-R" in /sbin/ifup at what seemed an appropriate spot.
Worked fine, though:-)
Rene
had the same problem
my /etc/dhclient.conf has just one line in it, worked a treat.
prepend domain-name-servers 127.0.0.1;
Ok, it is absolutely frivolous to post this, but perhaps someone may find it useful.
dhclient supports a number of hooks that control how the script interacts with the rest of the system, in this case, we wish to negate the adverse effects of rewriting /etc/resolv.conf everytime dhclient works it voodoo.
man dhclient-script for more info.
Anyways, create your resolv.conf then do this:
# vi /etc/dhclient-enter-hooks
make_resolv_conf() {
echo "doing nothing to resolv.conf"
}
# chmod 500 dhclient-enter-hooks
# chmod +x dhclient-enter-hooks
# killall dhclient
# dhclient interface
now you will notice that dhclient will reassuringly notify you that it is "doing nothing to resolv.conf".
And that’s it!
Cheers!
Hi there
This article is fairly old, but my two pence could be worth the while to somebody out there.
Yes, you are quite correct in that DHCP client overwrites the file /etc/resolv.conf.
The question that must be asked is where does the DHCP client get the info that it writes into /etc/resolv.conf? Well, the answer can only be, from the DHCP server!
So with all due respect your solution, it is like taking some medicine for a headache. Why not fix the root of the problem that causes the headache and leave the medicine alone? 🙂
Your DHCP server is incorrectly configured for your requirements.
So let’s fix it …
YOU WANT:
domain http://www.example.org
nameserver 10.0.0.1 # my min-dns server
nameserver 11.22.33.44
nameserver 11.22.33.45
So let us open up the DHCP server’s configuration file (BTW I use the standard FreeBSD isc-dhcpd installed via ports) …
These are the steps you need to go through:
1. Log into the DHCP server via SSH or physically,
2. su to get root access and log in,
3. Switch to the directory where "dhcpd.config" is located. For FreeBSD 5.x and above this is in /usr/local/etc
dhcpserver# cd /usr/local/etc
4. Open the file "dhcpd.conf" with "vi" or "ee" or your favourite editor
5. Find the section that contains your subnet settings. In your case it will read something like
subnet 10.0.0.0 netmask 255.255.255.0 {
6. Now all we need to do is add the domain name and the name servers you want. This is done with the "options" statement
7. In your case you will add to the section the following:
subnet 10.0.0.0 netmask 255.255.255.0 {
domain-name "www.example.org";
domain-name-servers 10.0.1.4;
domain-name-servers 11.22.33.44;
domain-name-servers 11.22.33.45;
….. rest of existing detail
}
8. Save and exit
9. Now we need to restart the DHCP server. First let us stop it gracefully. Enter at the prompt:
dhcpserver# ./rc.d/isc-dhcpd.sh stop
wait for the server to stop. A few messages will appear …
Now start it again by entering at the prompt the following:
dhcpserver# ./rc.d/isc-dhcpd.sh start
and wait for it to start.
10. Now go to your client machine. You might have been sitting at it all the while! 😉
11. Log in at your client machine
12. Switch to super user with "su" command and log in
13. OK now we need to renew our DHCP session. First you need to know what your interface name is. Let’s find that out by a simple ifconfig command. Enter at the command prompt:
myclient# ifconfig
Make a note (or mental one) of the NIC’s name – let say we find it is "fxp0"
So now to renew the FreeBSD DHCP session. Enter at the command prompt:
myclient# dhclient fxp0
and you will see a message appearing that give the new DHCP session details.
14. Check if your detail is now as you want it by entering:
myclient# more /etc/resolv.conf
You should (if all went well) see:
search "www.example.org"
nameserver 10.0.0.10
nameserver 11.22.33.44
nameserver 11.22.33.45
Well, I trust this helps somebody out here!