sudo: unable to resolve host test: Name or service not known
出现这个问题一般是自定义了主机名test,然后hosts中没找到对应的主机名
确认错误
robin@test:~$ host
输出如下:
test
表示test
是当前的hostname
重现错误
robin@test:~$ sudo
输出如下:
sudo: unable to resolve host test: Name or service not known
usage: sudo -h | -K | -k | -V
usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user]
usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command]
usage: sudo [-AbEHknPS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p prompt]
[-T timeout] [-u user] [VAR=value] [-i|-s] [<command>]
usage: sudo -e [-AknS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p prompt]
[-T timeout] [-u user] file ...
解决错误
robin@test:~$ cat /etc/hosts
输出:
127.0.0.1 localhost
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
可以看到,这里只有localhost
,没有test
,那么咱们只需要用vim
编辑器给他增加一行即可。
使用su - root
切换到root用户,或者使用sudo
robin@test:~$ sudo vim /etc/hosts
增加后
127.0.0.1 localhost
127.0.0.1 test
# The following lines are desirable for IPv6 capable hosts
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
再次检查
robin@test:~$ sudo
usage: sudo -h | -K | -k | -V
usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user]
usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command]
usage: sudo [-AbEHknPS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p prompt]
[-T timeout] [-u user] [VAR=value] [-i|-s] [<command>]
usage: sudo -e [-AknS] [-r role] [-t type] [-C num] [-g group] [-h host] [-p prompt]
[-T timeout] [-u user] file ...
成功