I messed up my /etc/hosts and /etc/resolv.conf files, now my network doesn't work. How can I reset it?
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).