How to restore/recreate etc/resolv.conf files

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?

Here is Solutions:

We have many solutions to this problem, But we recommend you to use the first solution because it is tested & true solution that will 100% work for you.

Solution 1

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

Solution 2

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

Solution 3

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

Solution 4

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
    

Solution 5

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

Note: Use and implement solution 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply