[problem help] sudo命令的奇怪特性 Resolved
Tofloor
poster avatar
neko
Moderator
2024-02-02 21:03
Author

突然发现sudo执行的速度变得很慢居然要5秒以上的时间。
image.png

然后查到了这个帖子

image.png

于是我查了一下当前的hosts配置文件,看起来没问题对吧。

image.png

然后我断开wifi连接执行time sudo发现启动时间变正常了。

image.png

于是猜想会不会是我设置了dns的关系,我之前把dns设置为了114.114.114.114,我改回成默认获取路由DNS后果然sudo的执行速度恢复了正常。

发现问题了吗?sudo执行的时候居然要先进行主机名解析,然后看看hosts文件的内容,破案了。

root@X16:~# cat /etc/hosts
127.0.0.1 localhost

# 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

系统安装的时候没有把主机名给写入进去,导致使用sudo的时候用公共dns先查询了主机名,直到它超时后fallback执行。

所以最后的解决方法就是把主机名加进去,改成这样:

root@X16:~# cat /etc/hosts
127.0.0.1 localhost X16

# 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

或者执行

echo "127.0.0.1 $HOSTNAME" | sudo tee -a /etc/hosts
Reply Favorite View the author
All Replies
jjcui8595
Moderator
2024-02-02 21:27
#1

感谢分享

Reply View the author
CPU你的❤️
deepin
2024-02-02 22:05
#2

好文章

Reply View the author