2

I made a mistake and accidentally deleted hosts file from my system and cannot figure out how to get back my hosts (/etc/) file, when I do

sudo service apache2 restart

It's showing:

sudo: unable to resolve host SystemName.

I am using Ubuntu 14.04 LTS. I tried editing the hosts file sudo vi hosts and put:

127.0.0.1       localhost
::1             localhost ip6-localhost ip6-loopback
fe00::0         ip6-localnet
ff00::0         ip6-mcastprefix
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters

But to no avail.

2

Seems like the issue is resolving the actual hostname of the machine you are on. Check your hostname by running the hostname command like this:

hostname

Or like this:

cat /etc/hostname

And let’s say your hostname is SystemName. Then you would have to add a line to your /etc/hosts file like this:

127.0.0.1       SystemName

So the whole /etc/hosts file would look like this:

127.0.0.1       localhost
127.0.0.1       SystemName
::1             localhost ip6-localhost ip6-loopback
fe00::0         ip6-localnet
ff00::0         ip6-mcastprefix
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters

You could also consolidate those 127.0.0.1 entries like this:

127.0.0.1       localhost SystemName

Then the final /etc/hosts file would look like this:

127.0.0.1       localhost SystemName
::1             localhost ip6-localhost ip6-loopback
fe00::0         ip6-localnet
ff00::0         ip6-mcastprefix
ff02::1         ip6-allnodes
ff02::2         ip6-allrouters

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.