Ubuntu ERROR: sudo: unable to resolve host ubuntu: Name or service not known

ubuntu系统报错:sudo: unable to resolve host ubuntu: Name or service not known

检查一下,

ubuntu@ubuntu:~/mc$ cat /etc/hostname

ubuntu

ubuntu@ubuntu:~/mc$ cat /etc/hosts

127.0.0.1 localhost

::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

修改一下,

sudo vim /etc/hosts

添加了一行"127.0.1.1 ubuntu"(也可以是127.0.0.1 ubuntu),如下,

127.0.0.1 localhost

127.0.1.1 ubuntu

# 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

再检查

username@ubuntu ~ $ cat /etc/hostname

ubuntu

username@ubuntu ~ $ cat /etc/hosts

127.0.0.1 localhost

127.0.1.1 ubuntu

::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

问题解决。

posted @ 2024-01-17 10:00  MasonLee  阅读(10)  评论(0编辑  收藏  举报