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.
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:
Your problem is no default route is available as you see (route commanr response). This isobviously because of dhcp failed. So now you can set your network manually or read dhclient man.
ip inside your network can be 10.0.0.4 or 192.168.0.4 .
Now you can set default route toyour gateway (router)
But you must get router ip first. Fortunately you set your interface ip and this is where your network address comes from (ip masked by netmask). To get your router ip requires change the address end .4 to some common number like 1 or 138 or 254. The router ip and client ip must belong to the same network to get ping functional.
So try: ping 10.0.0.1 first when you set your ip 10.0.0.4, etc.
If you can ping your router then set the default route:
sudo route default add gw <yourrouterip> eth0
Cool you can check your default route with the route command.
The last step is set your dns server. But check your default route before, just try ping some ip outside your network, like google dns server 8.8.8.8 .
Best Answer
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
:The commands used in the example are:
Here you are, few more approaches and explanations:
hostname
in/etc/hosts
through single command via commandline and Example how to find your current IP address;/etc/hosts/
purpose.