新版 Ubuntu 每次在 /etc/resolv.conf
修改DNS之后,重启就会失效。
永久修改需要编辑 /etc/systemd/resolved.conf
文件。
该文件默认内容如下:
# This file is part of systemd.
#
# systemd is free software; you can redistribute it and/or modify it
# under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; either version 2.1 of the License, or
# (at your option) any later version.
#
# Entries in this file show the compile time defaults.
# You can change settings by editing this file.
# Defaults can be restored by simply deleting this file.
#
# See resolved.conf(5) for details
[Resolve]
#DNS=
#FallbackDNS=
#Domains=
#LLMNR=no
#MulticastDNS=no
#DNSSEC=no
#Cache=yes
#DNSStubListener=yes
我们要做的就是取消 DNS
项的注释,并在后面填入合适的 DNS
服务器(可以多行)。
例如 DNS=119.29.29.29
,然后保存并重启 systemd-resolved
服务。
systemctl restart systemd-resolved.service
最后可以查看下修改结果。
systemd-resolve --status
终端回显:
root@ubuntu:~# systemd-resolve --status
Global
DNS Servers: 119.29.29.29
114.114.114.114
文章评论