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

本文提供了解决Ubuntu系统中使用sudo命令时出现sudo:unabletoresolvehost错误的方法,主要涉及修改/etc/hosts文件,确保主机名对应正确。


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.1	localhost

127.0.1.1	Lily-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 ?Reply With Quote


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.


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

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值