I messed up my /etc/hosts and /etc/resolv.conf files, now my network doesn't work. How can I reset it?

6,754

Solution 1

If you are running a currently-supported desktop version of Ubuntu, then networking should be handled by the NetworkManager service, and your /etc/network/interfaces file should contain only the default loopback interface definition

auto lo
iface lo inet loopback

To fix your /etc/resolv.conf file, you probably need to reconfigure the package from the command line using

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 - if so you should probably answer "No" to that one. This will re-create the default symbolic link in place of your manually-edited file.

Solution 2

Edit your /etc/network/interfaces with the correct settings.

sudo nano /etc/network/interfaces

Then restart your network device:

sudo ifdown eth0 && sudo ifup eth0

The resolv.conf will be recreated with the correct settings.

You can put the following in your hosts file if you want the defaults back:

127.0.0.1 localhost
127.0.1.1 hostname

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

The second line is only needed if your pc has a name. (Don't forget to substitue the name).

Share:
6,754

Related videos on Youtube

pritamprasad
Author by

pritamprasad

Updated on September 18, 2022

Comments

  • pritamprasad
    pritamprasad over 1 year

    I tweaked my system by installing ftp server and a dns server. I think in the process I messed up resolv.conf and the hosts file.

    Now I want to restore it but am not able to do so. I am using ubuntu 14.04 x86_64.

    Here is a screenshot that might help:

    enter image description here

    • user.dz
      user.dz almost 10 years
      Could you post the instructions you followed and the current content of related config files hosts...?
    • pritamprasad
      pritamprasad almost 10 years
      i added 127.0.1.1 myname to the resolv.conf file.. everything was fine then i rebooted and everything gone.
    • user.dz
      user.dz almost 10 years
      Resolv.conf is generated file, sure you have seen this at top of it # DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN. See askubuntu.com/questions/130452/…
    • steeldriver
      steeldriver almost 10 years
      You should include in your question the version of Ubuntu you are using and whether it is a server version or a desktop (GUI) version.
  • pritamprasad
    pritamprasad almost 10 years
    in my case i have wlan1, as i am using network through this, but the command [sudo ifdown wlan1 && sudo ifup wlan1] do not work for me.... it is giving error as [ignoring unknown interface]
  • Pabi
    Pabi almost 10 years
    Can you post the output or a screenshot of the output from sudo ifconfig and sudo ifdown wlan1
  • cosmos
    cosmos almost 9 years
    You are awesome..