为什么 resolv.conf 中的127.0.0.1 会导致DNS解析问题?

分享于 

4分钟阅读

ubuntu

  繁體

问题

当resolv.conf文件文件包含127.0.0.1 IP地址,许多域名就无法解析,出现超时了。

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


iface eth1 inet static


 address 162.226.130.121


 netmask 255.255.255.248


 network 162.226.130.120


 broadcast 162.226.130.127


 gateway 162.226.130.126



auto eth1:0


iface eth1:0 inet static


 name Local network


 address 192.168.1.1


 netmask 255.255.255.0


 network 192.168.1.0


 broadcast 192.168.1.255


 gateway 192.168.1.254



# bridge for virtual box


auto br0


iface br0 inet static


 address 192.168.2.1


 netmask 255.255.255.0


 network 192.168.2.0


 broadcast 192.168.2.255


 bridge_ports eth3


 bridge_stp off


 bridge_maxwait 0


 bridge_fd 0



启动后/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 127.0.0.1


search m2osw.com


nameserver 192.168.122.1


nameserver 206.13.31.12


nameserver 206.13.28.12



更新:

附带说明:如果我将/etc/resolvconf/resolv.conf.d/tail软链接指向/dev/null(如下所述),那么我会得到一个如下所示的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 127.0.0.1



总之,bug中提到了两个解决方案:

1)删除/etc/resolv.conf软链接,并用一个纯文件替换它。

2)更改你的bind9 设置,以便BIND可以响应这些本地DNS请求,

bind有一个示例设置,可以工作:


options {


 [...]


 forwarders {


 // Google DNSes


 8.8.8.8;


 8.8.4.4;


 };


 [...]


};




答案1

使用具有环回地址的dns服务器(例如127.0.0.1)导致问题:

resolvconf会忽略所有优先级较低的其他dns服务器。

dns服务器的优先级由定义dns服务器的网络接口定义。

请参见/etc/resolvconf/interface-orderman 5interface-order

幸运的是,有一个环境变量可以更改此行为:


TRUNCATE_NAMESERVER_LIST_AFTER_LOOPBACK_ADDRESS



请参见man 8resolvconf

如果是的话


TRUNCATE_NAMESERVER_LIST_AFTER_LOOPBACK_ADDRESS=no




答案2

使用静态IP声明polulate /etc/network/interfaces,就可以声明DNS名称服务器地址,我建议:


auto eth1


iface eth1 inet static


address 162.226.130.121


netmask 255.255.255.0


gateway 162.226.130.126 #Isn't the gateway actually xx.1??


dns-nameservers 8.8.8.8 162.226.130.126 #or any others you prefer.





network  DNS  网络  
相关文章