# 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
内容是一段警告:说这个文件是resolvconf程序动态创建的,不要直接手动编辑,修改将被覆盖。
所以我们不能直接修改这个文件了
查资料得到两种方法:
方法1:
sudo vim /etc/network/interfaces
dns-nameservers 8.8.8.8
方法2:(这个文件默认是空的)
sudo vim /etc/resolvconf/resolv.conf.d/base
nameserver 8.8.8.8nameserver 8.8.4.4
如果有多个DNS就一行一个
修改好保存,然后执行
resolvconf -u
sudo vim /etc/resolvconf/resolv.conf.d/head
打开里面显示如下
再看/etc/resolv.conf,最下面就多了2行:
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
nameserver 8.8.8.8nameserver 8.8.4.4
现在此DNS已经生效了,无需重启,当然重启也不会丢失
此外还有一种方法是修改/etc/resolvconf/resolv.conf.d/headsudo vim /etc/resolvconf/resolv.conf.d/head
# 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