Ubuntu – When I run a sudo command it says unable to resolve host

command line

And when I tried the following commands /etc/hostnames and /etc/hosts, it says:

bash: permission denied.

Best Answer

To to resolve a host, just add it to /etc/hosts, like the example below.

Animated example

Use ctrl+o to save the edits and ctrl+x to exit from Nano. Here you are and screenshot example.

In this example is assumed that the hostname (SZS in this case) is correct, but it is not bound to the server's IP address via server's hosts file.

To resolve this issue you must find (or set) your hostname and insert next line into /etc/host:    your-hostname

The commands used in the example are:

cat /etc/hostname      # the command 'cat' will print the content of '/etc/hostname' file
hostname               # without arguments, this command will do the same as above command
cat /etc/hosts         # will print the content of '/etc/hosts' file
sudo nano /etc/hosts   # 'nano' text editor will open '/etc/hosts' as root

Here you are, few more approaches and explanations: