要在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