I was given the files for a mini linux, that boots directly into firefox. It works for all it should be doing, only that I do not get an internet connection.

We have 3 DNS servers in the network, which all work. I can ping them, too. But when trying to ping google.de or wget google.de I get a bad address error.

nslookup google.de works for some reason.

I tracked the issue down to my resolv.conf on the booted system not having the same contents as the resolv.conf that I put into the .iso file.

I tried understanding all the factors that go into creating and modifying resolv.conf. I'm not quite sure I got it all, but I definitely didn't find my solution there.

So as a last ditch effort, I tried making the resolv.conf file immutable using

:~# chattr +i /etc/resolv.conf

When rebuilding and booting again to my surprise my file was renamed to resolv.conf~ and in its place was the same standard file that has been haunting me.

The file contents make me believe it gets the information from the network itself. When starting the .iso in Virtualbox without internet access, my file is being kept as it is.

I tried changing /etc/dhcp/dhclient.conf to not get the information from the net, by deleting domain-name-server and domain-name-search from the request part of the file.

Didn't work unfortunately.

I don't have the NetworkManager installed. The iso is based on Ubuntu 14.04.

There is probably vital information missing. I'm happy to provide it.


I think I found the file that clears resolv.conf.

It seems to be /usr/share/udhcpc/default.script


# udhcpc script edited by Tim Riker <[email protected]>

[ -z "$1" ] && echo "Error: should be called from udhcpc" && exit 1

[ - n "$broadcast" ] && BROADCAST="broadcast $broadcast"
[ -n "$subnet" ] && NETMASK="netmask $subnet"

case "$1" in
        /bin/ifconfig $interface
        for i in /etc/ipdown.d/*; do
            [ -e $i ] && . $i $interface

        /bin/ifconfig $interface $ip $BROADCAST $NETMASK

        if [ -n "$router" ] ; then
            echo "deleting routers"
            while route del default gw dev $interface ; do

            for i in $router ; do
                route add default gw $i dev $interface metric $((metric++))

        echo -n > $RESOLV_CONF # Start ----------------  
        [ -n "$domain" ] && echo search $domain >> $RESOLV_CONF
        for i in $dns ; do
            echo adding dns $i
            echo nameserver $i >> $RESOLV_CONF
        for i in /etc/ipup.d/*; do
            [ -e $i ] && . $i $interface $ip $dns 
        done # End ------------------

exit 0

It's part of the udhcpc program. A tiny dhcp client, that is part of busybox

Will investigate further.


I commented the part out (#Start to #End), that seemingly overwrites the /etc/resolv.conf file and sure enough. That was the culprit. So an obscure script caused all this trouble.

I changed the question to reflect, what actually needed to be known to solve my problem, so it would be easier to find for people with the same problem and so I could accept an answer.

Thanks for the help here in figuring things out.

  • 1
    Setting the immutable flag on resolv.conf doesn't work as you expected as the file was not changed. The directory entry in /etc was changed when the file was renamed. You'd have to set /etc to be immutable - something you really don't want to do.
    – doneal24
    Commented Dec 15, 2014 at 15:56
  • @DougO'Neal I see. Thanks for the heads up.
    – Minix
    Commented Dec 15, 2014 at 16:33

9 Answers 9

  1. You shouldn't manually update your resolv.conf, because all changes will be overwritten by data that your local DHCP server provides. If you want it to be static, run sudo dpkg-reconfigure resolvconf and answer "no" to dynamic updates. If you want to add new entries there, edit /etc/resolvconf/resolv.conf.d/base and run sudo resolvconf -u, it will append your entries and DHCP server's entries.

  2. Try to edit your /etc/network/interfaces and add your entries there, like

     auto eth0 
     iface eth0 inet dhcp 
     dns-search google.com 
     dns-nameservers dnsserverip 

and then restart /etc/init.d/networking restart or sudo ifdown -a and sudo ifup -a

  1. Your system uses udhcp which is a very small DHCP client program. The udhcp client negotiates a lease with the DHCP server and notifies a set of scripts when a leases is obtained or lost. You can read about it's usage here or just edit this script (as you did).
  • 8
    I did add the entries into the /etc/resolvconf/resolv.conf.d/base and ran resolvconf -u. It didn't work, unfortunately.
    – Minix
    Commented Dec 15, 2014 at 14:41
  • Have you tried to run sudo dpkg-reconfigure resolvconf? After running resolvconf -u, your entries wasn't in result file? How did you add them, like "nameserver" or "search google.com"?
    – kirill-a
    Commented Dec 15, 2014 at 14:55
  • I did run dpkg-reconfigure resolvconf. The entries were not in there. And I have entries with both nameserver ip and search domain.
    – Minix
    Commented Dec 15, 2014 at 14:59
  • No, running dpkg-reconfigure resolvconf won't add entries, but you can disable automatic updates. If you disable updates, you can edit resolv.conf manually and it shouldn't be overwritten.
    – kirill-a
    Commented Dec 15, 2014 at 15:04
  • 1
    My bad for phrasing it so clumsily, I was answering your comment sentence by sentence. After running resolvconf -u the entries were not added.
    – Minix
    Commented Dec 15, 2014 at 15:06

Ubuntu 16.04 If the network interfaces for your server instance is controlled by DHCP, the dhclient program will overwrite your /etc/resolv.conf file whenever the networking service is restarted.

You can fix the issue by editing the /etc/dhcp/dhclient.conf file and adding “supersede” statements for domain-name, domain-search and domain-name-servers as follows:

supersede domain-name "local.com";
supersede domain-search "local.com";
supersede domain-name-servers;

In this particular case the name server is located at "" and the domain name is "local.com"

Note that each line is terminated by a semi-colon and the domain name is enclosed in double quotes.

  • 3
    Unfortunately this didn't work on Ubuntu 18.04. After rebooting, /etc/resolv.conf was overwritten with Commented Oct 21, 2019 at 4:52
  • May be you can try this askubuntu.com/questions/1031279/… Commented Oct 21, 2019 at 10:21
  • Also check if you are running dnsmasq Commented Oct 21, 2019 at 10:22
  • In case you don't want to overwrite but just add yours before, you can use prepend instead of supersede
    – Wadih M.
    Commented Nov 28, 2022 at 15:13

I ran into this too. Commenting out domain-name-server didn't fix it for me either.

Also, I'm not using resolvconf, just plain /etc/resolv.conf.

I didn't try using chattr +i to lock down resolv.conf because it seems too hacky. Also, I want Puppet to be able to modify resolv.conf when necessary.

The best solution I found overrides the default behavior of dhclient using its documented hooks.

Create a new file at /etc/dhcp/dhclient-enter-hooks.d/nodnsupdate with the following contents:

make_resolv_conf() {

Then make the file executable:

chmod +x /etc/dhcp/dhclient-enter-hooks.d/nodnsupdate

Now when dhclient runs -- either on reboot or when you manually run sudo ifdown -a ; sudo ifup -a -- it loads this script nodnsupdate. This script overrides an internal function called make_resolv_conf() that would normally overwrite resolv.conf and instead does nothing.

This worked for me on Ubuntu 12.04.

  • 2
    Didn't work on Ubuntu 18.04 :( /etc/resolv.conf was overwritten after reboot. Commented Oct 21, 2019 at 4:50

In Azure VMs /etc/resolv.conf is not directly editable.

Try adding the DNS entries in your network configuration files /etc/sysconfig/network-scripts/ifcfg-eth0 and so on like below:


and restart the network service after saving the files. you will see the configuration will then be added into the resolve.conf as well.


My ubuntu 18.04 from OVH did not come with the /etc/network/interface file. It uses netplan to manage the ips and nameservers. File: /etc/netplan/50-cloud-init.yaml

# This file is generated from information provided by the datasource.  Changes
# to it will not persist across an instance reboot.  To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
            dhcp4: true
                macaddress: fa:16:3e:d8:f7:7b
            set-name: ens3
    version: 2

So I did as it said and created the File: /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg

# network: {config: disabled}
            dhcp4: true
                macaddress: fa:16:3e:d8:f7:7b
            set-name: ens3
                search: [mydomain.com]
    version: 2

I then applied the settings with netplan apply , rebooted and the old settings still came back. I then checked with ls -la /etc/resolv.conf and noticed it was soft-linked to:

/etc/resolv.conf -> ../run/systemd/resolve/stub-resolv.conf.

So I deleted the file, and made a new one.

rm -f /etc/resolv.conf  
{ echo "nameserver";
echo "nameserver;
echo "search mydomain.com"; } >  /etc/resolv.conf
chattr +i  /etc/resolv.conf

Everything works on reboot and my file is still intact and not linked. Just don't chattr +i /etc/resolv.conf if it soft-linked. Remove it first.


To make the DNS related changes in resolv.conf permanent, you need to change the DHCP configuration file named dhclient.conf. You can find the file in /etc/dhcp/dhclient.conf.

Open the file for editing (don't forget to use sudo). You’ll see lines like these:

#supersede domain-name "fugue.com home.vix.com";
#prepend domain-name-servers;

Remove the preceding “#” and use the domain-name and/or domain-name-servers which you want. Save it. Now the DNS related changes will be permanent (i.e. inside resolv.conf file).

Credits goes to: https://itsfoss.com/resolvconf-permanent-ubuntu/

  • This answer had already been given 2 years earlier. Commented Oct 21, 2019 at 4:53
  • @DanDascalescu Not really. The main answer says you should add new lines to the file, while my answer says you should just uncomment these two lines. Also, the lines are not the same. Commented Sep 16, 2020 at 8:28
  • This didn't work for me in Azure VM. The resolv.conf file still doesn't show the prepended domain-name-server after a reboot.
    – alelom
    Commented Jun 10 at 12:11

I am not using systemd-resolved, just dhcpcd on an OVH VM running Arch Linux.

On reboot I always got a new resolv.conf with "domain openstacklocal" and the OVH DNS server. Commenting-out the options for domain_name_servers and domain_search in /etc/dhcpcd.conf did not help.

I finally got it to stop overwriting my resolv.conf by putting the line "nohook resolv.conf" into my /etc/dhcpcd.conf file. I found this from reading "man dhcpcd.conf".


go to this directory:

  cd /etc/resolvconf/resolv.conf.d

Open the file named head and put the DNS IPs or names in there. Open the file named tail and put the domain in there. Reboot.

  • That directory doesn't exist by default on Ubuntu 18.04. Do you need to install a service that creates it? Commented Oct 21, 2019 at 4:55

Use the below command to prevent the resolv.conf or any file from overwriting after reboot:

chattr -V +i filename e.g chattr -V +i /etc/resolv.conf

To revert back the change use the below command:

chattr -i filename - to re-enable insert to the file

chattr (Change Attribute) is a command line Linux utility that is used to set/unset certain attributes to a file in Linux system to secure accidental deletion or modification of important files and folders, even though you are logged in as a root user.

  • 1
    I believe that the user in the question actually tried chattr, but obverved that this had no effect.
    – Kusalananda
    Commented Oct 15, 2019 at 21:25
  • This will work for sure , The option user tried is for editing the file not for making it immutable Commented Oct 16, 2019 at 13:09
  • Please run the command with sudo chattr -V +i filename e.g sudo chattr -V +i /etc/resolv.conf Commented Oct 16, 2019 at 13:16
  • The simple trick is to remove /etc/resolv.conf first. Then remake it with your own name servers and search domain. Then chattr +i /etc/resolv.conf
    – Vituvo
    Commented May 9, 2021 at 7:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .