安装好Ubuntu之后设置了静态IP地址,再重启后就无法解析域名。想重新设置一下DNS,打开/etc/resolv.conf
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
内容是一段警告:说这个文件是resolvconf程序动态创建的,不要直接手动编辑,修改将被覆盖。
果不其然,修改后重启就失效了,搜索了Ubuntu下设置DNS的相关资料,总结出两个办法:
方法一通过/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
可以看到我们的设置已经加上了,然后再ping一个域名,当时就可以解析了,无需重启。
附:CentOS下修改DNS则容易的多了,直接修改/etc/resolv.conf,内容是:
nameserver 8.8.8.8
nameserver 8.8.4.4
保存就生效了,重启也没问题。
文章转载自:http://www.yubosun.com/tech/ubntu-dns-reset.htm
原文链接:https://www.f2er.com/ubuntu/351898.html