sudo:无法解析主机ubuntu-server

每次我尝试使用sudo都会得到这个:

 sudo: unable to resolve host ubuntu-server 

我的/etc/hosts文件:

 127.0.0.1 localhost 127.0.1.1 ubuntu-server # 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 

/etc/hostname具有:

 ubuntu-server 

我认为有一些其他设置导致unable to resole host错误,但我找不到这些。

编辑/etc/hosts ,你有一个错字127.0.1.1不是loopback,把它改成127.0.0.1 ,保存并重启。

这可能意味着您的DNS查找已损坏。

你的/ etc / hosts文件看起来很好。 你想要它看起来像这样:

 127.0.0.1 localhost 127.0.1.1 ubuntu-server 

但是有几种合法的变体。

确保/ etc / hostname中有匹配的主机名。

检查/etc/resolv.conf以查看是否定义了工作名称服务器。

看看你是否可以解析任何主机名。 nslookup google.com有效吗? 如果没有,则DNS查找失败,原因可能是配置或网络或防火墙问题(可能超出了您对服务器的控制)。

根据我的经验, sudo最终会询问您的密码,并在域查找超时后授予您提升的权限。

尝试手动将正确的DNS名称服务器添加到/etc/resolv.conf。

在紧要关头,您可以使用公共服务器。 以下是使用Google DNS服务器的文件:

 /etc# cat resolv.conf nameserver 8.8.8.8 nameserver 8.8.4.4 nameserver 2001:4860:4860::8888 nameserver 2001:4860:4860::8844