要在Debian系统上修改DNS服务器,您可以按照以下几种方法进行操作:
/etc/resolv.conf
文件这是最简单和直接的方法。通过编辑此文件可以手动添加或修改DNS服务器的配置。
nano
)打开 /etc/resolv.conf
文件:sudo nano /etc/resolv.conf
nameserver 8.8.8.8
nameserver 8.8.4.4
netplan
配置网络(适用于Debian 9及以上版本)nano
)打开 /etc/netplan/01-netcfg.yaml
文件:sudo nano /etc/netplan/01-netcfg.yaml
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
addresses: [192.168.1.100/24]
gateway4: 192.168.1.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
sudo netplan apply
systemd-resolved
配置网络(适用于Debian 9及以上版本)nano
)打开 /etc/systemd/resolved.conf
文件:sudo nano /etc/systemd/resolved.conf
# DNS=8.8.8.8 8.8.4.4
DNS=8.8.8.8 8.8.4.4
systemd-resolved
服务以应用更改:sudo systemctl restart systemd-resolved
无论使用哪种方法,都可以通过以下命令验证DNS设置是否生效:
/etc/resolv.conf
文件:cat /etc/resolv.conf
nslookup
或 dig
命令测试DNS服务器是否能够正常解析域名:nslookup example.com