Gav*_*son 7 domain-name-system dnsmasq
我正在我的大学网络中建立一个小型专用网络。我有一个 Centos 6 盒子(sun)位于我的专用网络和大学 WAN 之间。sun上的 eth0通过 netgear 智能交换机连接到 WAN 和 eth1 到我的专用网络。sun充当专用网络的路由器,使用使用 iptables 配置的 NAT 将流量从 eth1 转发到 eth0。专用网络(目前只有Mercury)上的客户端通过在sun上运行的 dnsmasq 分配了 IP、网关等和主机名。dnsmasq 配置为将特定 IP 和主机名发送到客户端的 MAC 地址。
我只/etc/hosts
在sun上对主机名/IP 进行了硬编码:
# cat /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.42.1 sun sun.beowulf.iecs
192.168.42.2 mercury mercury.beowulf.iecs
Run Code Online (Sandbox Code Playgroud)
目前,eth0(面向广域网)的 IP 地址是通过 DHCP 分配的(无论如何,sun eth0 始终分配相同的 IP;这就是大学的工作方式,但我正在更改此地址以允许我分配一个静态IP)。我/etc/resolv.conf
的太阳是:
; generated by /sbin/dhclient-script
search biol.uregina.ca
nameserver 142.3.102.202
nameserver 142.3.100.15
Run Code Online (Sandbox Code Playgroud)
当我重新启动时似乎被覆盖了所以我有以下内容 /etc/dnsmasq-resolv.conf
search beowulf.iecs biol.uregina.ca
nameserver 127.0.0.1
nameserver 8.8.8.8
Run Code Online (Sandbox Code Playgroud)
并已指示 dnsmasq 使用它而不是 /etc/resolv.conf
# Change this line if you want dns to get its upstream servers from
# somewhere other that /etc/resolv.conf
resolv-file=/etc/dnsmasq-resolv.conf
# By default, dnsmasq will send queries to any of the upstream
# servers it knows about and tries to favour servers to are known
# to be up. Uncommenting this forces dnsmasq to try each query
# with each server strictly in the order they appear in
# /etc/resolv.conf
strict-order
Run Code Online (Sandbox Code Playgroud)
大多数情况下,此设置有效。我的问题(我不知道这是一个主要的,但是......)是nslookup
和dig
两个未能解决名字太阳和汞 ,除非我告诉这些命令其DNS服务器查询:
# nslookup sun.beowulf.iecs sun.beowulf.iecs
Server: sun.beowulf.iecs
Address: 192.168.42.1#53
Name: sun.beowulf.iecs
Address: 192.168.42.1
# nslookup sun sun.beowulf.iecs
Server: sun.beowulf.iecs
Address: 192.168.42.1#53
Name: sun
Address: 192.168.42.1
# nslookup sun
Server: 142.3.102.202
Address: 142.3.102.202#53
** server can't find sun: NXDOMAIN
# nslookup sun.beowulf.iecs
Server: 142.3.102.202
Address: 142.3.102.202#53
** server can't find sun.beowulf.iecs: NXDOMAIN
Run Code Online (Sandbox Code Playgroud)
对mercury而不是**sun*给出了相同的输出。代表性dig
输出为:
# dig @192.168.42.1 mercury.beowulf.iecs
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> @192.168.42.1 mercury.beowulf.iecs
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 65090
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0
;; QUESTION SECTION:
;mercury.beowulf.iecs. IN A
;; ANSWER SECTION:
mercury.beowulf.iecs. 0 IN A 192.168.42.2
;; Query time: 0 msec
;; SERVER: 192.168.42.1#53(192.168.42.1)
;; WHEN: Wed Jun 25 12:05:31 2014
;; MSG SIZE rcvd: 54
Run Code Online (Sandbox Code Playgroud)
当我没有指定要使用的名称服务器时不工作:
# dig mercury.beowulf.iecs
; <<>> DiG 9.8.2rc1-RedHat-9.8.2-0.23.rc1.el6_5.1 <<>> mercury.beowulf.iecs
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 29153
;; flags: qr rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 0
;; QUESTION SECTION:
;mercury.beowulf.iecs. IN A
;; AUTHORITY SECTION:
. 7988 IN SOA a.root-servers.net. nstld.verisign-grs.com. 2014062500 1800 900 604800 86400
;; Query time: 0 msec
;; SERVER: 142.3.102.202#53(142.3.102.202)
;; WHEN: Wed Jun 25 12:05:37 2014
;; MSG SIZE rcvd: 113
Run Code Online (Sandbox Code Playgroud)
在上面的最后一个示例 ( dig
) 中,它SERVER: 142.3.102.202#53(142.3.102.202)
是第一个 DNS 服务器,/etc/resolv.conf
因此默认情况下,sun似乎正在使用此名称服务器而不是 dnsmasq,因为/etc/dnsmasq.conf
.
那么,这是一个问题吗?我可以从sun ping sun和mercury,并使用SSH从sun连接到mercury。
如果这是一个问题(或者即使不是),有没有办法配置sun并dnsmasq
在其上运行以自动解析私有主机名?
dig
(域信息搜索器)和nslookup
(交互式查询 Internet 名称服务器)是查询名称服务器的工具。除非将特定名称服务器指定为命令行参数,否则它们将查询在 /etc/resolv.conf 中找到的名称服务器。他们只是不查看主机信息的替代来源,例如/etc/hosts
文件或/etc/nsswitch.conf
.
如果你想在你的sun主机上通过 dnsmasq 强制所有 dns 查询,/etc/resolv.conf
那里应该指向 dnsmasq,即它应该看起来像:
#/etc/resolv.conf on sun
nameserver 127.0.0.1
Run Code Online (Sandbox Code Playgroud)
为了防止该文件在重新启动网络接口 eth0 时被覆盖,请编辑/etc/sysconfig/network-scripts/ifcfg-eth0
并添加选项 PEERDNS=no
其次,/etc/dnsmasq-resolv.conf
您尝试将 dnsmasq 配置为将自身用作上游名称服务器nameserver 127.0.0.1
......该文件应如下所示:
#/etc/dnsmasq-resolv.conf
search beowulf.iecs biol.uregina.ca
nameserver 8.8.8.8
Run Code Online (Sandbox Code Playgroud)
如果您想使用 Google 的名称服务器。使用大学名称服务器 142.3.102.202 和 142.3.100.15 可能是个好主意,因为某些资源只能从校园网络中看到并不少见。
如果您的Mercury主机是由 DHCP 配置的,它应该从 dnsmasq 获取它的配置,并且/etc/resolv.conf
那里指向 192.168.42.1 上的 dnsmasq 名称服务器