[size=13.3333px]如题,Ubuntu 20.04 LTS 版本安装之后,发现偶尔报错 Temporary failure in name resolution,搜索一番之后大部分意见认为是系统的DNS设置不全面,建议重新设置一下DNS。
按照网上的文章,直接修改的是/etc/resolv.conf ,原文内容如下:
nameserver 127.0.0.536 P+ |6 u/ A, x8 \- |! r
options edns0 trust-ad
" r( I+ C' c9 o( L$ Y直接添加新的dns,例如:
nameserver 8.8.8.8
h/ f8 Z0 k; f$ R) ]2 P; Fnameserver 114.114.114.114
3 K: B9 k, m# a* R0 v4 v结果reboot重启之后,还是原来的内容不变,仔细查看才发现/etc/resolv.conf本身在第一行的注释里面已经写了“Do not edit"。经过查阅相关资料,找到如下方法可以修改Ubuntu20.04 LTS版本的DNS,
首先修改 /etc/systemd/resolved.conf 文件,在其中添加dns信息,例如:
DNS=8.8.8.8 114.114.114.114
, o5 V0 _/ Q& D然后退出保存。
然后以root身份在ubuntu终端中依次执行如下命令:
systemctl restart systemd-resolved
. o( s& {2 W% l2 N8 Fsystemctl enable systemd-resolved2 ]1 a* l# T# q, ]/ x
+ R4 ^6 l" t+ r% Emv /etc/resolv.conf /etc/resolv.conf.bak
M0 J4 w: l: ?* ^& ]& cln -s /run/systemd/resolve/resolv.conf /etc/) S5 z7 w: o. z, n5 M/ G
再查看/etc/resolv.conf文件就可以看到新的dns信息已经写入其中了。
) _7 E4 U! X0 E8 f