|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?立即注册
×
搬瓦工的默认DNS是这样的:
- nameserver 172.31.255.x
- nameserver 8.8.8.8
- nameserver 1.1.1.1
复制代码
无论你是直接用搬瓦工控制面板里的默认系统,还是自己dd系统(dd系统:脚本重装系统),都会通过 DHCP 传播污染 DNS 配置。
后果是什么?
答:后果就是部分网站ip解析会绕路,比如下面ping谷歌的结果。
- ➜ ~ ping google.com
- PING google.com (64.233.185.113) 56(84) bytes of data.
- 64 bytes from yb-in-f113.1e100.net (64.233.185.113): icmp_seq=1 ttl=107 time=49.4 ms
- 64 bytes from yb-in-f113.1e100.net (64.233.185.113): icmp_seq=2 ttl=107 time=48.9 ms
- 64 bytes from yb-in-f113.1e100.net (64.233.185.113): icmp_seq=3 ttl=107 time=48.7 ms
- 64 bytes from yb-in-f113.1e100.net (64.233.185.113): icmp_seq=4 ttl=107 time=49.2 ms
- 64 bytes from yb-in-f113.1e100.net (64.233.185.113): icmp_seq=5 ttl=107 time=48.6 ms
复制代码
搬瓦工为什么要这样做?
因为历史遗留问题,原来有的搬瓦工机器没法解锁 DNS,部分流媒体和 gpt 有地区限制。因此瓦工默认做了 DNS 解锁。但是现在已经不需要这样做了。
如果你手动修改 /etc/resolv.conf 中的配置,那么每次重启后,都会自动被 DHCP 污染 DNS。每次重启都要修改一遍很麻烦。
今天介绍一种简单的方法,来避免这种情况:
一句话命令:
- sudo bash -c 'chattr -i /etc/resolv.conf 2>/dev/null || true; rm -f /etc/resolv.conf; printf "nameserver 1.1.1.1\nnameserver 8.8.8.8\nnameserver 2606:4700:4700::1111\nnameserver 2001:4860:4860::8888\n" > /etc/resolv.conf; chattr +i /etc/resolv.conf'
复制代码
作用是将dns配置修改为:
- nameserver 1.1.1.1
- nameserver 8.8.8.8
- nameserver 2606:4700:4700::1111
- nameserver 2001:4860:4860::8888
复制代码
修改后再尝试 ping google:
- ➜ ~ ping google.com
- PING google.com (142.250.176.14) 56(84) bytes of data.
- 64 bytes from lax17s51-in-f14.1e100.net (142.250.176.14): icmp_seq=1 ttl=120 time=0.640 ms
- 64 bytes from lax17s51-in-f14.1e100.net (142.250.176.14): icmp_seq=2 ttl=120 time=0.599 ms
- 64 bytes from lax17s51-in-f14.1e100.net (142.250.176.14): icmp_seq=3 ttl=120 time=0.443 ms
复制代码
可以看到,延迟下降了许多。并且之后再重启机器也无需重新修改了。
对于dhcp,我尝试通过下面的方法覆盖,理论上应该有效果,但是实际上不生效。
- echo 'supersede domain-name-servers 1.1.1.1, 8.8.8.8, 2606:4700:4700::1111, 2001:4860:4860::8888;' | sudo tee -a /etc/dhcp/dhclient.conf
复制代码 |
|