一般情况下,Linux 可以通过修改 /etc/resolv.conf
或是 /etc/network/interfaces
来修改DNS,但ubuntu18以上,打开 /etc/network/interfaces
会看到这句话
# ifupdown has been replaced by netplan(5) on this system. See
# /etc/netplan for current configuration.
# To re-enable ifupdown on this system, you can run:
# sudo apt install ifupdown
ifupdown 已经被 netplan 代替,因此我们需要修改netplan的配置文件。
进入目录 /etc/netplan
,你会看到一个yaml文件 ( 01-netcfg.yaml
或 50-cloud-init.yaml
),打开它修改 nameservers 下的 addresses
network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: no
addresses:
- 192.168.121.199/24
gateway4: 192.168.121.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4] <==
然后运行下列命令
sudo netplan apply
可通过下面命令验证配置是否生效
systemd-resolve --status | grep 'DNS Servers' -A2
Powered by Froala Editor
发表评论 (对文章评论)