[size=13.3333px]如题,Ubuntu 20.04 LTS 版本安装之后,发现偶尔报错 Temporary failure in name resolution,搜索一番之后大部分意见认为是系统的DNS设置不全面,建议重新设置一下DNS。
按照网上的文章,直接修改的是/etc/resolv.conf ,原文内容如下:
nameserver 127.0.0.53
* \1 `9 [- ^/ D8 c5 q1 ?4 ooptions edns0 trust-ad4 g) G: u, e" O w# H, d& R$ h2 v# }
直接添加新的dns,例如:
nameserver 8.8.8.8
1 d# s; e' d8 K% `0 E/ Tnameserver 114.114.114.114
* _4 N3 K4 z' T/ y结果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
: w6 f0 R- z2 V* |1 T然后退出保存。
然后以root身份在ubuntu终端中依次执行如下命令:
systemctl restart systemd-resolved
* E! C7 X# I/ a8 q* S6 Isystemctl enable systemd-resolved
( X6 }! R3 {; n; J3 E" z \& I& k, W) r1 E1 j* |% K
mv /etc/resolv.conf /etc/resolv.conf.bak* t: S/ k, a0 ], o: z. y, A$ K
ln -s /run/systemd/resolve/resolv.conf /etc/
/ @' `4 V m: k# T再查看/etc/resolv.conf文件就可以看到新的dns信息已经写入其中了。
# o4 C7 }) L4 i- C