方法一 通过/etc/network/interfaces,在它的最后增加一句:
dns-nameservers 8.8.8.8
8.8.8.8是Google提供的DNS服务,这里只是举一个例子,你也可以改成电信运营商的DNS。重启后DNS就生效了,这时候再看/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.8
方法二 通过修改:
/etc/resolvconf/resolv.conf.d/base(这个文件默认是空的)
在里面插入:
nameserver 8.8.8.8
nameserver 8.8.4.4
如果有多个DNS就一行一个
修改好保存,然后执行
resolvconf -u
再看/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.8
nameserver 8.8.4.4
可以看到我们的设置已经加上了,然后再ping一个域名,当时就可以解析了,无需重启。