- 臨時生效(隨時會被刷掉)
關閉systemd-resolved進程
# systemctl stop systemd-resolved
# echo "nameserver 8.8.8.8" /etc/resolv.conf
- 永久生效(使用ystemd-resolved, ubuntu18.04以及之后的版本默認使用此工具管理dns)
(方案一)
2.1 安裝resolvconf工具
# apt install resolvconf
2.2 配置
# echo "nameserver 8.8.8.8" >/etc/resolvconf/resolv.conf.d/head
2.3 更新配置
# resolvconf -u
2.4 檢查配置是否生效
# cat /etc/resolv.conf
nameserver 8.8.8.8
方案二
2.1 打開 /etc/systemd/resolved.conf,修改為
[Resolve]
DNS=8.8.8.8 # 設置的是域名解析服務器的IP地址
#FallbackDNS=
#Domains=
LLMNR=no # 設置的是禁止運行LLMNR(Link-Local Multicast Name Resolution),否則systemd-resolve會監聽5535端口
#MulticastDNS=no
#DNSSEC=no
#Cache=yes
#DNSStubListener=yes
2.2 重新啟動systemd-resolved服務
$ sudo systemctl restart systemd-resolved
2.2.3 查看當前dns狀態
$ sudo systemd-resolve --status
Global
DNS Servers: 8.8.8.8
...