Ubuntu 12.10 DNS 配置

本文不建议直接修改Ubuntu 12.10的/etc/resolv.conf或resolvconf配置文件,而是推荐遵循文档提示,通过在interfaces文件中设置dns-nameservers,并调整interface-order文件来设置DNS优先级。当遇到DNS故障时,确保已安装resolvconf并重启系统以解决问题。
摘要由CSDN通过智能技术生成

首先不推荐修改/etc/resolv.conf或者修改/etc/resolvconf/resolv.conf.d/目录下的head,base文件,添加tail文件的方法也不赞成。

因为resolv.conf和head文件中都有提醒文字:

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

cat /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

不要对这个视若无睹。以为即便你当时改对了,网络服务一重启,又不行了。


用man resolvconf命令查看文档,可以看到一段提醒注意的文字:

N.B.: On a machine where resolvconf has just been or is about to be installed and which previously relied on a static /etc/resolv.conf file, the nameserver  informa‐
       tion in that static file should be migrated to the appropriate iface stanza(s) in interfaces(5).
证明了的确不推荐修改上面的文件,而建议修改/etc/network/interfaces文件。下面是个正确的例子:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
      address 10.112.18.106
      network 10.112.18.0
      netmask 255.255.255.0
      broadcast 10.112.18.255
      gateway 10.112.18.254
      dns-nameservers 10.112.18.1

就是最后一行dns-nameservers,可以添加多个,用空格分开


上面我用的是静态IP地址,很多时候需要使用DHCP动态分配IP, 这个时候dns-nameservers仍然能够使用,不过优先级比DHCP提供的dns要低。可以改变这个优先级,通过修改/etc/resolvconf/interface-order配置文件。


现在用nslookup来查找dns,一切正常:

nslookup google.com
Server:		10.112.18.1
Address:	10.112.18.1#53

Non-authoritative answer:
Name:	google.com
Address: 74.125.224.229
Name:	google.com
Address: 74.125.224.224
Name:	google.com
Address: 74.125.224.238
Name:	google.com
Address: 74.125.224.230
Name:	google.com
Address: 74.125.224.232
Name:	google.com
Address: 74.125.224.227
Name:	google.com
Address: 74.125.224.233
Name:	google.com
Address: 74.125.224.231
Name:	google.com
Address: 74.125.224.225
Name:	google.com
Address: 74.125.224.226
Name:	google.com
Address: 74.125.224.228


但是,我的一台服务器用上面的方法仍然有故障。

用下面的命令没有问题,interfaces文件中的dns配置会被自动复制到/etc/resolv.conf文件中

ifdown eth0; ifup eth0

但是如果用service networking restart就不行了。

解决方法是:

1.确定安装了resolvconf

apt-get install resolvconf
2. 重新配置resolvconf

dpkg-reconfigure resolvconf
确认框中都选择yes.

3.然后重新启动,问题解决。






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值