37

I deleted both the resolvconf folder and the resolv.conf file in /etc by mistake, assuming that resolvconf was causing UCK to fail. Now the application has upgraded, fixing the issue, but it says no file named resolv.conf in /etc. What it says is correct because I deleted those files. Is there any way to recreate the files or restore from another location?

muru
  • 197,895
  • 55
  • 485
  • 740
beeju
  • 2,973
  • 4
  • 19
  • 22

5 Answers5

52

You could reinstall resolvconf to restore the default configuration:

sudo apt-get install --reinstall resolvconf

Another idea would be remove "resolvconf" and then install:

sudo apt-get remove --purge resolvconf && sudo apt-get install resolvconf
muru
  • 197,895
  • 55
  • 485
  • 740
desgua
  • 32,917
  • 4
    Amplification: to ensure that resolvconf is fully restored you have to purge it and install it again, then reboot. If you don't purge it but only remove it then it won't install the symlink at /etc/resolv.conf on reinstall. If you don't reboot then resolvconf's database will generally be missing nameserver information until you do reboot... or reconfigure (down and up) all active interfaces. – jdthood Oct 28 '12 at 20:19
  • 4
    This broke my internet, and now I can't fetch any packages from the ubuntu repos. – dessalines Mar 30 '16 at 16:54
  • 4
    This also broke internet, uninstalled, reinstall failed, and now I cant update anything. – Chris Oct 07 '17 at 00:00
  • 8
    If you find yourself unable to fetch new packages, ping us.archive.ubuntu.com on another computer, grab the straight IP address returned and use that in a wget (ie: wget http://91.189.91.26/ubuntu/pool/main/r/resolvconf/resolvconf_1.78ubuntu4_all.deb) then install using dkpg (ie: dpkg -i resolvconf_1.78ubuntu4_all.deb) and reboot. Alternative would be to put the IP in your /etc/hosts just to get the update/install to complete. – vandsh Oct 12 '17 at 01:04
  • ln: cannot remove '/etc/resolv.conf': Device or resource busy – 1rq3fea324wre Jul 24 '18 at 21:02
  • @vandsh the link ubuntu/pool/main/r/resolvconf is not valid, under r is no resolvconf. – Timo Apr 30 '22 at 13:41
  • 4
    When you're dealing with a file that controls whether the computer can resolve domain names, please do not suggest uninstalling something and then reinstalling it when reinstalling it will not work when DNS is broken. – Chai T. Rex Dec 15 '22 at 15:53
17

If resolvconf -u shows the WARNING that /etc/resolv.conf is not a symbolic link to /run/resolvconf/resolv.conf then just backup that resolv.conf and make the symbolic link:

$ cd /etc
$ sudo ln -s /run/resolvconf/resolv.conf
luart
  • 960
  • 6
    This should be the accepted answer! How would you reinstall resolvconf when you can't resolve hostnames?! – Evils Apr 05 '16 at 14:00
6

Try this:

nano /etc/resolv.conf

add:

nameserver 8.8.8.8

nameserver 192.168.x.x (check your ifconfig output for the correct address)

then

sudo service resolvconf start
sudo systemctl enable resolvconf
Zanna
  • 70,465
  • re-installing resolvconf is probably a better idea – pim Dec 04 '17 at 15:45
  • This would only affect things temporarily. The /etc/resolv.conf file would be overwritten since it's managed by the resolvconf package. – TheZeke Nov 04 '20 at 09:28
5

The accepted answer did not work for me. After reinstalling resolvconf, the system would completely wipe my resolv.conf file after each reboot.

To fix this, I had to reinstall the network-manager and libnss-resolve packages in addition to resolvconf.

  1. Manually add a nameserver to resolve.conf (this is so you can fetch packages from the Ubuntu repos):

    1. sudo vi /etc/resolv.conf
      
    2. Add nameserver 8.8.8.8 to the file.
  2. Reinstall the network-manager, libnss-resolve, and resolvconf packages:

    apt install --reinstall resolvconf network-manager libnss-resolve
    
mthrl
  • 51
  • 1
    Good answer. If your dns resolution is broken, this gets you back to working, so you can effect other repairs. – Kevin Buchs Feb 09 '23 at 13:51
-2

Have you emptied your trash, if not, you can restore from trash.