resolv.conf is being modified, and not by me (a DHCP problem)

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
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:


What I wanted:

nameserver	# my min-dns server

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.

what resolv.conf contains after a reboot:


Here’s what I want it to contain:

nameserver		# my min-dns server

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

prepend {
 domain-name "";

I tried that.  Then did the following to restart dhclient:

bash# cat /var/run/
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

After several attempts. No luck.

prepend domain-name "";

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


Now I’m getting the following /etc/resolv.conf file:


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 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 " "

After restarting dhclient, /etc/resolv.conf
contains the following:


Note: I still need to do the following to get ed1 running after restarting dhclient:

ifconfig ed1 inet

So the next thing I try doing is the supersede command:

supersede domain-name " "

OK!  That gives me:


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

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
which recommends this file:

# cat /etc/dhclient-enter-hooks
make_resolv_conf() {
      echo "doing nothing to resolv.conf"

See dhclient-script(8) for details.

5 thoughts on “resolv.conf is being modified, and not by me (a DHCP problem)”

    1. 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:-)


  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!


  2. 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 …

    nameserver # my min-dns server

    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 netmask {

    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 netmask {
    domain-name "";
    ….. 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/ 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/ 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 ""

    Well, I trust this helps somebody out here!

Leave a Comment

Scroll to Top