发现 Firefox
的状态栏长时间显示 Looking up www.xxxx.com ...
,应该是我的电脑的 DNS
配置出问题了。
/etc/resolv.conf
内容如下:
# Generated by resolvconf search lan nameserver 8.8.8.8 nameserver 192.168.111.1
/etc/resolvconf.conf
内容如下:
resolv_conf=/etc/resolv.conf name_servers=8.8.8.8
我配置的是使用静态DNS 8.8.8.8
,但是 /etc/resolv.conf
文件内容多出了两项,怀疑是 search lan
引起。
很多的网络管理工具都会去改动 /etc/resolv.conf
文件,如 pdnsd
dnsmasq
NetworkManager
。
禁止 NetworkManager
改动 /etc/resolv.conf
修改
/etc/NetworkManager/NetworkManager.conf
配置dns=none
重新载入
systemd
配置sudo systemctl daemon-reload
重启
NetworkManager
sudo systemctl restart NetworkManager
重新生成
/etc/resolv.conf
sudo resolvconf -u
# Generated by resolvconf nameserver 8.8.8.8
现在可以正常上网了。
但是静态DNS
8.8.8.8
不太稳定,最好换成优先使用DHCP分配的本地DNS。
使用DHCP分配的本地DNS
撤销之前对
/etc/NetworkManager/NetworkManager.conf
的修改dns=default
去掉
/etc/resolvconf.conf
配置的静态DNSresolv_conf=/etc/resolv.conf #name_servers=8.8.8.8
重新载入
systemd
配置sudo systemctl daemon-reload
重启
NetworkManager
sudo systemctl restart NetworkManager
重新生成
/etc/resolv.conf
sudo resolvconf -u
# Generated by resolvconf nameserver 192.168.111.1
过一会儿
/etc/resolv.conf
内容自动被更新# Generated by resolvconf search lan nameserver 192.168.111.1
search lan
又出现了,NetworkManager
貌似是通过dhclient
对/etc/resolv.conf
进行修改的,具体指令参见/sbin/dhclient-script
。上网又很流畅了,看来之前上网慢是由
8.8.8.8
DNS服务器抽风引起,与search lan
配置无关。