标签:
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程序动态创建的,建议不要直接手动编辑,修改的值可能被覆盖。
果不其然,修改后重启就失效了。
设置DNS有以下两个办法:
方法一: 通过/etc/network/interfaces,在它的最后增加一句(多个dns之间用空格分隔):
dns-nameservers 202.97.224.68 202.97.224.69
202.97.224.68是联通的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 202.97.224.68
nameserver 202.97.224.69
方法二 :通过修改/etc/resolv.conf(这个文件默认是空的)
在里面插入:
nameserver 202.97.224.68
nameserver 202.97.224.69
如果有多个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 202.97.224.68
nameserver 202.97.224.69
可以看到设置的多个DNS已经加上了,然后再ping一下百度,立即就可以解析了,无需重启。
标签:
原文地址:http://www.cnblogs.com/wangzhigang/p/5460526.html