1

Yes, Might be duplicate of following links Tried both links solutions but didn't worked for me.

  1. Error message when I run sudo: unable to resolve host (none)

  2. sudo: unable to resolve host ubuntu-server

Following is my /etc/hosts output:

127.0.0.1 kaushal
120.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost.com


# 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

Following is my /etc/hostname output:

127.0.0.1 kaushal
120.0.0.1 localhost.localdomain localhost
127.0.0.1 localhost.com

Every time when I write command sudo apt-get update I get following error message.

sudo: unable to resolve host 127.0.0.1kaushal

Also in my terminal I get kaushal@127:~$ as following screenshot. enter image description here

It was not like that before.

All this started happening after I change my username from

All Setting >  Details > Device name

Any suggestion what's wrong with my machine?? How can I resolve this problem. Let me know if you want more details.

Kaushal Suthar
  • 265
  • 4
  • 13
  • Have you tried deleting the line `127.0.0.1 localhost.com` , save changes and then reboot your machine? – Dominic Motuka Jun 11 '16 at 20:21
  • Also try to interchange the lines such like : `127.0.0.1 localhost.localdomain localhost` comes first then `127.0.1.1 kaushal` where `kaushal` is your machine name. – Dominic Motuka Jun 11 '16 at 20:32
  • Yes I did that too. – Kaushal Suthar Jun 11 '16 at 20:37
  • Suthar there's a typo in **127.0.0.1 kaushal**...it's supposed to be **127.0.1.1 kaushal** – Dominic Motuka Jun 11 '16 at 20:40
  • Maybe, I've checked my hostname file and now it has only my name. There is nothing like "127.0.0.1 kaushal" so I guess that was the problem. – Kaushal Suthar Jun 11 '16 at 20:42
  • @Suthar Did that solve the problem? – Dominic Motuka Jun 11 '16 at 20:45
  • I didn't try this one "127.0.1.1 kaushal ", Check my update in question. – Kaushal Suthar Jun 11 '16 at 20:46
  • Please don't put the solution in the question. Instead, edit the solution out of your question and put it in the answer space. You can then accept your own answer. – chaskes Jun 11 '16 at 20:47
  • It doesn't matter (much) if the short name is associated with 127.0.0.1 or 127.0.1.1 -- the latter is a Debian/Ubuntu specific thing, where the hostname configured in the installer is added to /etc/hosts. In the good old days there was only a single entry, listing the hostname first and localhost second. – Simon Richter Jun 11 '16 at 23:50

2 Answers2

4

I solved the problem by going to
All Setting > Details > Device Name
changed the device name to kaushal
Just make sure that your /etc/hostname file has only your machine name.For my case it was kaushal

Dominic Motuka
  • 1,191
  • 2
  • 13
  • 24
Kaushal Suthar
  • 265
  • 4
  • 13
1

I will answer your question specifically
In your /etc/hosts for localhost change 127.0.0.1 kaushal to
127.0.1.1 localhost localhost.localdomain kaushal

Dominic Motuka
  • 1,191
  • 2
  • 13
  • 24