Linux Make Sure /etc/resolv.conf Never Get Updated By DHCP Client

I am using GNU/Linux with the Internet Systems Consortium DHCP Client. The dhclient, provides a means for configuring one or more network interfaces using the Dynamic Host Configuration Protocol. It also updates my /etc/resolv.conf file each time my laptop connects to the different network. I would like to keep my existing nameservers. How do I skip /etc/resolv.conf update on a Linux based system? How do I stop DHCP client from changing resolv.conf on Linux?

Tutorial details
Difficulty level Intermediate
Root privileges Yes
Requirements ISC DHCP client
Est. reading time 5m
[/donotprint]The DHCP protocol allows a host to contact a central server which maintains a list of IP addresses which one can assign to one or more subnets. This protocol reduces system administration workload, allowing devices to be added to the network with little or no manual configuration.

WARNING! Many firewalls only allow access to specific nameservers only. So make sure your nameservers are supported. Also, many corporates block snooping name server such as OpenDNS due to privacy issues.

Make Sure /etc/resolv.conf never get updated By DHCP client

Information regarding DNS servers are stored in /etc/resolv.conf file. One can see it with cat command:
$ cat /etc/resolv.conf
Linux Make Sure /etc/resolv.conf Never Get Updated By DHCP Client
You can set or change DNS server by editing the /etc/resolv.conf file. However, this file might get updated by dhcp client on Linux. There are various methods to fix this issue. Use any one of the following methods. Let us see how to stop DHCP from changing resolv.conf file on Linux.

Write protecting /etc/resolv.conf file

Method 1: I am going to write protect your /etc/resolv.conf file using the chattr command on a Linux bases system. The syntax is:
# chattr +i /etc/resolv.conf
The +i option (attribute) write protects /etc/resolv.conf file on Linux so that no one can modify it including root user. You can use chflags command on FreeBSD based system.

Creating dhclient-script hooks

Method 2: The DHCP client network configuration script is invoked from time to time by dhclient. This script is used by the dhcp client to set each interface’s initial configuration prior to requesting an address, to test the address once it has been offered, and to set the interface’s final configuration once a lease has been acquired. This script is not meant to be customized by the end user. If local customizations are needed, they should be possible using the enter and exit hooks provided. These hooks will allow the user to override the default behavior of the client in creating a /etc/resolv.conf file. 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 behavior, redefine this function in the enter hook script.

Create hook to avoid /etc/resolv.conf file update

You need to create /etc/dhcp/dhclient-enter-hooks.d/nodnsupdate file under a Debian / Ubuntu Linux:
# vi /etc/dhcp/dhclient-enter-hooks.d/nodnsupdate
Append following code:


Save and close the file. Set permissions using the chmod command:
# chmod +x /etc/dhcp/dhclient-enter-hooks.d/nodnsupdate
The script will replace make_resolv_conf() with our own function. This functions does nothing and so no IP address will get added to /etc/resolv.conf file.

A note about resolvconf program on a Debian or Ubuntu based system

If the resolvconf program is installed, you should not edit the resolv.conf configuration file manually on a Debian or Ubuntu based system as it will be dynamically changed by programs in the system. If you need to manually define the nameservers (as with a static interface), add a line something like the following to the interfaces configuration file at /etc/network/interfaces file:

##Place the line indented within an iface stanza, e.g., right after the gateway line.##

A note about RHEL / CentOS / Fedora Linux

Place following code in /etc/dhclient-enter-hooks file:
# vi /etc/dhclient-enter-hooks
Append code:


Save and close the file. Another option is to modify your interface configuration file such as /etc/sysconfig/network-scripts/ifcfg-eth0 file and append any one of the following option:

# do not overwrite /etc/resolv.conf ##


## use the following nameservers in /etc/resolv.conf ##

Save and close the file. Where,

  1. PEERDNS=yes|no – Modify /etc/resolv.conf if peer uses msdns extension (PPP only) or DNS{1,2} are set, or if using dhclient. default to “yes”.
  2. DNS{1,2}=<ip address> – Provide DNS addresses that are dropped into the resolv.conf file if PEERDNS is not set to “no”.

Configure dhclient.conf file

Method 3: The /etc/dhclient.conf or /etc/dhcp/dhclient.conf file contains configuration information for dhclient. You can turn on or off DNS update and other options for specific interface or all interface using this file. The man pages for DHCLIENT.CONF and DHCP-OPTIONS point out that in dhclient.conf, you should add this:

supersede domain-name-servers,;


prepend domain-name-servers,;

Here is a sample config for you:

       timeout 60;
       retry 60;
       reboot 10;
       select-timeout 5;
       initial-interval 2;

       interface "eth0" {
           send host-name "";
           send dhcp-client-identifier 00:30:48:33:BC:32;
           send dhcp-lease-time 3600;
           supersede domain-search "", "", "";
           prepend domain-name-servers,;
           request subnet-mask, broadcast-address, time-offset, routers,
                domain-search, domain-name, domain-name-servers, host-name;
           require subnet-mask, domain-name-servers;

How to stop network-manger updating /etc/resolv.conf on Linux

Method 4: Edit the /etc/NetworkManager/NetworkManager.conf file using a text editor such as vim command or nano command:
$ sudo vi /etc/NetworkManager/NetworkManager.conf
Add/edit/append as follows in [main] dns=none
Here is a full config:


Save and close the file in vim text editor. Next time you reboot the Linux box your /etc/resolv.conf file will not get updated when using nm (network-manager) on Linux.

Further readings:

🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 33 comments so far... add one

CategoryList of Unix and Linux commands
Disk space analyzersncdu pydf
File Managementcat
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
33 comments… add one
  • matias Sep 9, 2008 @ 5:14

    in Debian & *ubuntus resolv.conf is handled by a package called resolvconf. You should modify resolv.conf through it.

  • Lacey Sep 10, 2008 @ 2:04

    resolvconf will append whatever’s in your resolvconf files (head, base, tail), but I haven’t figured out a way to stop it from including the DHCP stuff as well, which I don’t want. I will try write-protecting /etc/resolv.conf to see if that works.

  • James Sep 12, 2008 @ 3:02

    Note: You are making a big assumption, that being that the user is using ext3. Yes RH and derivatives force this on you. Other linux distro’s recognize the other files systems where chattr is not going to be available.

    Take a look at the man page for dhclient.conf (used by dhclient3 btw)


    The supersede statement

    supersede [ option declaration ] ;

    If for some option the client should always use a locally-configured value or values rather than
    whatever is supplied by the server, these values can be defined in the supersede statement.

    *******end snip ***********

  • 🐧 nixCraft Sep 12, 2008 @ 4:19


    Thanks for your feedback. The faq has been updated.

  • eli Sep 21, 2009 @ 20:40

    Thanks so much for this. It’s been driving me crazy trying to keep resolv.conf from being changed.

  • yannis t Dec 20, 2009 @ 2:26

    if you want local values to supersede server values add in /etc/dhclient3/dhclient3.conf
    supersede domain-name “”

  • korhan Feb 16, 2010 @ 1:07

    At least on the BSD variants, the problem occurs when /sbin/dhclient-script is called by /sbin/dhclient. You could conceivably edit this script to ensure that /etc/resolv.conf does not get overwritten, but I find using the supersede directive works well enough. You would edit /etc/dhclient.conf as follows:

    supersede host-name “myhost”;
    supersede domain-name “my.domain”;
    supersede domain-name-servers,,;

    Which will give generate the following /etc/resolv.conf for you every time:

    search mydomain

    There really should be a more obvious way to stop this often unwanted behavior.

    Thanks for the information – you helped solve this irritating little problem for me.

  • ozgur Mar 11, 2010 @ 18:27

    My OS is kubuntu 9.10 x64. I have followed the procedure described in the 2nd Option, but it didn’t work.. resolv.conf is still being set to its original state everytime I reboot my system. Any of you can help me about it?

    • Kanda Nov 19, 2011 @ 17:18

      when you run dhclient eth0 chek which file is the correct configuration file


      put supersede command in the correct configuration file

  • 🐧 nixCraft Mar 11, 2010 @ 18:55

    Follow option # 3, this should fix it.

  • ozgur Mar 15, 2010 @ 19:27

    Thanks for the help, that did not fix the problem but then I tried using supersede command instead of option, and now it works

  • Peter Apr 1, 2010 @ 15:28

    For RHEL/CentOS the right way to solve this problem is to update /etc/sysconfig/network-scripts/ifcfg-eth0 or whatever interface you have, with:
    PEERNTP=no # if you have also problem with overwritten /etc/ntp.conf

    check documentation at /usr/share/doc/initscripts-*/sysconfig.txt
    or see whats inside script causing all this /sbin/dhclient-script , search for PEER

  • lifeofguenter Dec 1, 2010 @ 15:05

    In Debian Lenny (5.0) you should do this:

    # nano /etc/default/dhcpcd
    # Uncomment this to allow dhcpcd to set the DNS servers in /etc/resolv.conf
    # If you are using resolvconf then you can leave this commented out.

    # Uncomment this to allow dhcpcd to set hostname of the host to the
    # hostname option supplied by DHCP server.

  • Ron Jan 30, 2011 @ 11:40

    Hi all,
    When i use a vpn to my work i want the dns servers from my work to be used for queries to the local domain.

    Is there a way to point the client to a specific dns server for domain
    “mywork.local” ? When i connect the vpn resolv.conf does not get rewritten with the mywork dns servers…

    I use ubuntu 10.10 desktop edition

  • Michael V. Antosha Mar 14, 2011 @ 13:45

    Option # 3 needs correction I think.

    In my case there was not dhclient.conf file and I created an empty one with the line you proposed:
    option domain-name-servers a.b.c.d

    Nothing changed in behaviour and there was an error in logs when dhclient started:
    …dhclient: /etc/dhclient.conf line 2: expecting “code” keyword.

    Finally this worked for me (choose one of those):
    supersede domain-name-servers;
    prepend domain-name-servers a.b.c.d;

    ‘prepend’ does not replace DNS servers obtained by DHCP, but this makes your name server to be the first one in resolv.conf
    ‘supersede’ totally replaces the option with your variant.

    I hope this will help someone.


  • Martin Jul 21, 2011 @ 4:53

    The stub resolver (built into libc) can’t handle different directions for multiple domains, but you could always point it at a localhost resolver that does.

    For that you will need to learn about BIND or LWres or Unbound or some other DNS server, none of which is within the scope of this question.

    Having done that you’ll need to be a bit careful what you put in the “search” path; if you put VPN-only zones in it then there may be delays when you don’t have the VPN connected — not to mention, numerous entries in /var/log/named (or syslog) complaining about the unreachability of the DNS server at the other end of the VPN.

  • Fernando Jan 31, 2012 @ 5:24

    Thanks a lot, on slackware 13.37 only the write protection solves the problem.

  • Nikolay Mar 14, 2012 @ 7:29

    very helpful !
    I usually like to run my own dns on localhost, but from some time I am using DHCP for the IP because I am on Wireless.

  • William Mar 15, 2012 @ 17:52

    Option 3:
    option domain-name-servers,,

    Is broken (for me). Instead as Michael V. Antosha stated use

    supersede domain-name-servers,;
    prepend domain-name-servers a.b.c.d;

    Then issue a “sudo dhclient wlan0” from the command prompt. If you don’t know what the name if your interface is try “sudo ifconfig -a”

  • Ashish Jaiswal Mar 29, 2012 @ 19:30

    That is what I was looking for..

    Basically we have to let know the dhclient what are nameserver and domain-name ..
    I have added like this

    supersede host-name “server”;
    supersede domain-name “”;
    prepend domain-name-servers;

    And have removed domain-name and hostname from request line also.. so dhclient doesn’t have to look for this two parameter.. only just name-server

    which give me output of resolve.conf like this

    ashish@server:~$ cat /etc/resolv.conf
    # Generated by NetworkManager

  • Dan May 16, 2012 @ 9:00

    chattr +i /etc/resolv.conf

    And of course this has many great uses.

  • Christian Bolliger Jun 23, 2012 @ 7:45

    On RHEL:
    The hook script doesn’t replace make_resolv_conf() it will just run additionally. As mentioned before PEERDNS=no is the official solution.
    Of course you can use the hook script to rechange your resolv.conf to the values you need.

  • pouya Sep 21, 2012 @ 8:38

    EDIT /etc/sysconfig/network-scripts/ifcfg-eth0


  • rohit Dec 4, 2012 @ 7:23

    In the similar way can i make my dhclient to receive IP on virtual interface also ie on eth0 and eth0:1 ? i tried it with using different client-identifier for each virtual interface and dhcp server also seems to assign them different IP but somehow only the IP offered last is configured on interface and no ip is configured on virtual interface..

  • LV Mar 30, 2013 @ 19:21

    In RHEL/CentOS, you can simply add option: PEERDNS=”no” to your network interface script (/etc/sysconfig/network-scripts/ifcfg-ethX).

  • simon Sep 4, 2013 @ 5:32

    under ubuntu 12.04

    cat < /etc/network/if-up.d/
    if [ “${METHOD}” != “dhcp” ]; then
    return 0;
    if [ -f /var/run/resolvconf/interface/${LOGICAL}.dhclient ]; then
    resolvconf -d ${LOGICAL}.dhclient

    and in /etc/network/interfaces run the script as a post-up for dhcp interfaces

    auto eth0
    iface eth0 inet dhcp
    pre-up sleep 2
    post-up /etc/network/if-up.d/

    • simon Sep 4, 2013 @ 5:33

      the cat line should be:

      cat < /etc/network/if-up.d/

      • simon Sep 4, 2013 @ 5:35

        hm. the post is getting mangled … i’ll try html. the cat line once more

        cat <<‘EOF’ > /etc/network/if-up.d/

  • Antonio Nov 9, 2013 @ 14:04

    In CentOS there is another way to do that: set PEERDNS=no

  • Robert Jan 3, 2014 @ 8:54

    I had try all kind of 3 way you said, but I can’t resolve it.
    whenever OS connect network it change /etc/resolv.conf file.

    most above line is changed like this…
    “; generated by /sbin/dhclient-script”

    and nameserver ip was changed.


  • Vorms Jun 6, 2014 @ 18:22

    I add a file /etc/dhcp3/dhclient-enter-hooks.d/nodnsupdate with a empty make_resolv_conf() but these function doesn’t repalce the original function.
    I don’t undertand why ?

    Many thanks for your help,
    Best regards.


  • someguy Aug 7, 2014 @ 18:00

    Thanks very much for this.

    I’ve gone with the “redefine make_resolv_conf” approach in CentOS 6.5 and it works a treat!

  • zamaan Jun 24, 2016 @ 8:37

    Thank you.

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum