ubuntu 下修复使用sudo命令后出现主机名字不能解析的错误:Fix Ubuntu sudo Error:unable to resolve host

时间:2021-07-09 13:30:46


1.症状:

当你是使用sudo来执行命令时,总是在命令执行时,首先输出:“sudo:unable to resolve host Lily-desktop”(假设Lily-desktop 是你的当前主机的名字(host-name)), 但是怎样才能使使用sudo像以前一样不错误提示,正常工作呢。

 

when you’re running commands with sudo at beginning.It outputs “sudo:unable to resolve host Lily-desktop”(here assume current host-name is Lily-desktop),however the commands work as well as before.

 

 

2.产生该症状的原因:

这种症状经常发生在更改了hostname的情形下。在通过 编辑  /etc/hostname 改变了主机名字(hostname)之后, 我们还需要改变 /etc/hosts文件的相应部分的内容

 

This always happens after host-name changed.After change host-name by edit /etc/hostname,we also need to do a change in /etc/hosts file.

 

3.解决方案:

Solve:
Edit /etc/hosts:   // 编辑  /etc/hosts 文件

gksudo gedit /etc/hosts

make it looks like (change boldfaced words to current host-name): //使粗体字对应的词与当前的主机名即hostname 一致

127.0.0.1localhost

127.0.1.1Lily-desktop




# The following lines are desirable for IPv6 capable hosts

::1 localhost ip6-localhost ip6-loopback

fe00::0 ip6-localnet

ff00::0 ip6-mcastprefix

ff02::1 ip6-allnodes

ff02::2 ip6-allrouters

ff02::3 ip6-allhosts


本文的原始链接:http://ubuntuguide.net/fix-ubuntu-sudo-errorunable-to-resolve-host



You must have a host file problem. Please post this:

Code:
Prompt>sudo cat /etc/hosts


This is a correct /etc/hosts file entry:

Code:
127.0.0.1 localhost

127.0.1.1 jason.laptop



# 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

ff02::3 ip6-allhosts


Sometimes using the Network-Manager tool it will add a suffix to the localhost entry causing this.


Make your change to the host file and try again.

HTH,


i try to do that i got this

tonjaa@tonjaa-desktop:~$ sudo cat /etc/hosts
sudo: unable to resolve host tonjaa-desktop
127.0.0.1 localhost
127.0.1.1 tonjaa-desktop.domain.com

# 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
ff02::3 ip6-allhosts


then how i can do for resolve ?ubuntu 下修复使用sudo命令后出现主机名字不能解析的错误:Fix Ubuntu sudo Error:unable to resolve host


Try this. Use you favorite editor. VI or GEDIT and attempt to remove the:

.domain.com tail of this line:

Code:
127.0.1.1 tonjaa-desktop.domain.com


should be:

Code:
127.0.1.1 tonjaa-desktop

So to edit it:

Code:
sudo vi /etc/hosts

or

Code:
sudo gedit /etc/hosts

This should do it for you. Once you have edited the file. Save it and try again.

HTH,

Jaysunn

 


thank you very much i can edit it .
tonjaa@tonjaa-desktop:~$ sudo -s
root@tonjaa-desktop:~#

now it's ok. ubuntu 下修复使用sudo命令后出现主机名字不能解析的错误:Fix Ubuntu sudo Error:unable to resolve host


以上对话解决问题来自:http://nixcraft.com/ubuntu-debian/13543-ubuntu-sudo-unable-resolve-host.html