0

I recently changed my Ubuntu 15.10 laptop's name to Nick-Laptop: Ubuntu and now whenever I use sudo I get the error

sudo: unable to resolve host Nick-Laptop: Ubuntu

However the command still runs, for example:

nick@Nick-Laptop: Ubuntu:~$ sudo hostname
sudo: unable to resolve host Nick-Laptop: Ubuntu
Nick-Laptop: Ubuntu

I can also run sudo apt-get update and other commands just fine, it gives the error every time. I did some searching, which pointed me at /etc/hostname and /etc/hosts possibly mismatching but I believe I have the right values in both:

nick@Nick-Laptop: Ubuntu:~$ cat /etc/hostname
Nick-Laptop: Ubuntu
nick@Nick-Laptop: Ubuntu:~$ cat /etc/hosts
127.0.0.1   localhost
127.0.1.1   Nick-Laptop: Ubuntu

# 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

What could be going wrong?

1

Why would you change your hostname to something containing spaces? Please restrict your hostname to the characters given in this SO answer:

The Internet standards (Requests for Comments) for protocols mandate that component hostname labels may contain only the ASCII letters 'a' through 'z' (in a case-insensitive manner), the digits '0' through '9', and the hyphen ('-'). The original specification of hostnames in RFC 952, mandated that labels could not start with a digit or with a hyphen, and must not end with a hyphen. However, a subsequent specification (RFC 1123) permitted hostname labels to start with digits. No other symbols, punctuation characters, or white space are permitted.

If you want to show random crap in your prompt, then change your prompt, not your hostname.

  • My error came from using the term "Device name" in my search, which was used interchangeably with hostname in my search results. The device name doesn't have the restriction as I have fixed my hostname, which fixed the error, while keeping my laptop's device name the way I want it. Sorry for not realizing the error was with the characters in the hostname, but all the answers that came from searching my error had the answer "Make sure the name in /etc/hostname and /etc/hosts match and that should fix it". – Nick Welna Mar 1 '16 at 22:07

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.