Ubuntu系解决DNS查询慢与解析故障 Jun 25th 2018 Words: 263
This post is created 2 years ago, the content may be outdated.

在使用repo sync同步源码过程中,经常性出现如下错误:

1
2
3
4
fatal: unable to access 'https://github.com/omnirom/android_bootable_recovery/': Could not resolve host: github.com
fatal: unable to access 'https://github.com/omnirom/android_external_fuse/': Could not resolve host: github.com
fatal: unable to access 'https://github.com/omnirom/android_bootable_recovery/': Could not resolve host: github.com
fatal: unable to access 'https://github.com/omnirom/android_external_fuse/': Could not resolve host: github.com

已知问题与路由DNS设置无关,通过pingnslookup命令得到以下结果:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[email protected] ~ $ nslookup github.com
Server: 127.0.1.1
Address: 127.0.1.1#53

Non-authoritative answer:
Name: github.com
Address: 52.74.223.119
Name: github.com
Address: 13.229.188.59
Name: github.com
Address: 13.250.177.223

[email protected] ~ $ ping github.com
ping: unknown host github.com

其中nslookup的返回时间大概是10s,远超过超时阈值。由Server一栏可以得知Ubuntu系默认使用本地dnsmasq缓存查询。
精力有限,咱不对dnsmasq的故障进行深究,直接通过以下方式关闭dnsmasq。

编辑器打开/etc/NetworkManager/NetworkManager.conf

dns=dnsmasq注释掉,并sudo systemctl restart network-manager重启网络。

查看/etc/resolve.conf,确保DHCP给出的DNS在列表中。

完成配置。


EOF