各个发行版的Linux对于IP地址和DNS的配置是各不相同,最近在尝试使用Kali Linux,按照百度的说明配置完IP地址和DNS,重启主机以后DNS总是恢复成默认,试了好几种方法,最后经过测试,直接在interfaces文件中添加DNS设置才是有效的方法。
kali@kali:~$ cat /etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
allow-hotplug eth0
#iface eth0 inet dhcp
iface eth0 inet static
address 你的IP地址
netmask 子网掩码
gateway 网关
dns-nameservers DNS1 DNS2
重启网络或者系统后,查看/etc/resolv.conf文件,已经有了正确的DNS。
kali@kali:~$ cat /etc/resolv.conf
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
# 127.0.0.53 is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.
nameserver DNS1
nameserver DNS2
修改/etc/resolvconf/resolv.conf.d/base文件的方法经测试无效。