When I run a sudo command it says unable to resolve host [duplicate]
To to resolve a host, just add it to /etc/hosts
, like the example below.
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
:
127.0.1.1 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:
- Another answer of this question;
- Another answer of similar question;
-
Example how to be append the
hostname
in/etc/hosts
through single command via commandline and Example how to find your current IP address; - Bug discussion about this issue;
-
A brief explanation of
/etc/hosts/
purpose.
I'm assuming you're on Ubuntu Server.
/etc/hosts
and /etc/hostname
are files. You can use nano
or pico
to edit them if you're new to the OS. These files are owned by root, thus you need to use sudo
to edit them.
Thus, the full command would be sudo nano /etc/hosts
or sudo nano /etc/hostname
If you're on Ubuntu Server it's more advisable to use sudo hostname your.fqdn.com
. This will automatically update the /etc/hostname
file, however, if it doesn't you can always add the FQDN of your server into that file.
You will need to log out / log in to SSH to have these changes take effect for your session.
You can try sudo -i gedit /etc/hosts
.
To edit the file in the terminal itself, use sudo vim /etc/hosts
(advanced).
If you break something in this file, here's a fix.