I was changing my DHCP IP address to static on my server by sudo gedit /etc/network/interfaces and managed to edit the file and save it.

I then went to change resolv.conf but then it went blank and every time I rebooted it was blank.

I then deleted it by accident.

Now I can't install anything with apt-get or aptitude.


/etc/resolv.conf is automatically generated upon reboot by resolvconf if its a symbolic link to /run/resolvconf/resolv.conf (the file resolvconf writes to), you don't need to create it or edit it. You can put your name servers in /etc/network/interfaces using the following syntax so that they get added to /etc/resolv.conf automatically:

dns-nameservers <IP_address> <IP_address> <IP_address>

For example:


you should add this line at the end of your static IP configuration block.

If you have removed the symlink /etc/resolv.conf, run sudo dpkg-reconfigure resolvconf and you will come up with a set of questions to set it right again. Now do a reboot or run the following:

sudo ifdown eth0 && sudo ifup eth0  ##Change interface name accordingly

Everything should be fine.

| improve this answer | |
  • I tried adding that but it doesn't bring back the deleted resolv.conf file. When I run sudo cat /etc/resolv.conf it says no such file or directory. – John Moore Apr 12 '15 at 23:52
  • 2
    Run this sudo ln -s /var/run/resolvconf/resolv.conf /etc/resolv.conf then sudo ifdown eth0 && sudo ifup -v eth0 ..replace eth0 with your interface name.. – heemayl Apr 12 '15 at 23:58
  • @JohnMoore you said you tried adding dns server to /etc/resolv.conf, is that right ? Dns name servers should only be added to /etc/resolvconf/resolv.conf.d/base file . Or head file. – Sergiy Kolodyazhnyy Apr 13 '15 at 1:55
  • 1
    If you have manually overwritten the symlink with a file, you may need to run sudo dpkg-reconfigure resolvconf - it will present you with a question about preparing /etc/resolv.conf for dynamic updates - answer "Yes". It may also present you with another question about temporarily appending your existing config to the dynamic one - I suggest answering "No" to that one. – steeldriver Apr 13 '15 at 3:20
  • Resolvconf does not write to /etc/resolv.conf. It writes to /run/resolvconf/resolv.conf. This only affects the behavior of the resolver if /etc/resolv.conf is a symbolic link to /run/resolvconf/resolv.conf. – jdthood Apr 14 '15 at 11:14

To restore the symbolic link /etc/resolv.conf -> ../run/resolvconf/resolv.conf, execute the command sudo dpkg-reconfigure resolvconf at a command prompt.

If you are configuring your Internet-facing network interface using the ifup utility (whose configuration file is /etc/network/interfaces) then add nameserver information to the corresponding stanza in /etc/network/interfaces. Usually this entails adding at least a dns-nameservers option to the stanza in question. E.g.,

iface eth0 inet static

Then when you ifup eth0, the address will be added by resolvconf to resolv.conf (on an option line: nameserver

| improve this answer | |

You could also run:

sudo ln -s /run/resolvconf/resolv.conf /etc/resolv.conf

To restore the symbolic link.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.