Ubuntu: "unable to resolve host" when running sudo or other commands


Installed Ubuntu and ran "sudo" command, and I'm getting "unable to resolve host". The message "unable to resolve host" is occurring because the hostname was changed. The initial hostname during the installation of Ubuntu was something else and after the installation, the hostname was changed.
  • Changing the hostname:
Open Terminal (Ctrl + Alt + T)
tiyiworo@jzkdell:~$ sudo vi /etc/hostname

The the message "unable to resolve hsotname" started appearing.

To resolve the message "unable to resolve hostname", the new hostname also need to be added in the "hosts" file at /etc/hosts.

  • Elevate to super user
tiyiworo@jzkdell:~$ sudo su
sudo: unable to resolve host jzkdell
[sudo] password for tiyiworo:
  • Open /etc/hosts in vi editor with elevated permissions
root@jzkdell:/home/tiyiworo# sudo vi /etc/hosts
  • Edit out the old hostname with the new hostname
Before:       localhost       Dell-Vostro-1014

After:       localhost       jzkdell


[ To quit vi editor, press : (colon) and press q! and press enter]

tiyiworo@jzkdell:~$ sudo su

Now, the message "unable to resolve host is no more seen.

[Ubuntu 16.04 LTS]

Comment with Facebook