我的dnsmasqconfiguration为:
所有通过DHCP注册的“* .lan”主机都可以很好地解决:dnsmasq知道哪些IP分配给哪个主机名。 但是,从/ etc / hosts读取“rtfm.lan”并parsing为127.0.0.1。
我可以防止读取/ etc / hosts中的dnsmasq并手动添加地址:
no-hosts address=/rtfm.lan/192.168.1.2
但是这不是灵活的:如果有一天我决定改变我的IP,我也必须在dnsmasq.conf中改变它。
我怎么能告诉dnsmasq使用本地主机名与其真正的IP?
以防万一..这是我的DNSmasqconfiguration:
# Never forward plain names (without a dot or domain part) domain-needed # Never forward addresses in the non-routed address spaces. bogus-priv # Read resolv.conf serially strict-order #==========[ NAMESERVER ]==========# # Cache size cache-size=4096 # Don't read /etc/hosts no-hosts # Read additional hosts-file (not only /etc/hosts) to add entries into DNS addn-hosts=/etc/hosts-dnsmasq # Auto-append <domain> to simple entries in hosts-file expand-hosts #=== HOSTNAME OVERRIDES address=/localhost/127.0.0.1 # *.localhost => 127.0.0.1 #==========[ DHCP ]==========# # Enable for the local network? dhcp-authoritative # Tell MS Windows to release a lease on shutdown dhcp-option=vendor:MSFT,2,1i #=== DHCP # Domain name domain=lan # DNS-resolve hosts in these domains ONLY from /etc/hosts && DHCP leases local=/lan/ # DHCP range & lease time dhcp-range=192.168.1.70,192.168.1.89,24h # Default route dhcp-option=3,192.168.1.1 #=== FIXED LEASES # LAN MY HOSTS dhcp-host=00:23:54:5d:27:fa, rtfm.lan, 192.168.1.2 dhcp-host=00:23:54:5d:27:fb, rtfm.lan, 192.168.1.2 dhcp-host=c8:0a:a9:45:f1:03, 00:1e:64:9e:e9:5e, wtf.lan, 192.168.1.3
通常情况下,您可以在/etc/hosts定义静态主机,并在dnsmasq.conf文件中启用hosts 。 dnsmasq允许你为这个文件指定一个替代名字。
如果你想把rtfm.lan定址为192.168.1.2那么在192.168.1.2 rtfm.lan添加一行到/etc/hosts 。 正常情况下,您的主机文件的dnsmasq应该是可移植到所有的服务器。
在rtfm.lan ,IP栈会使路由短路,而不会将stream量发送到networking上。
如果更新/etc/hosts文件并用HUP信号发信号通知dnsmasq ,将会重新读取主机文件并应用更改。
编辑:dnsmasq不是为它自己的主机提供dynamic主机地址。 如前所述,它从DHCP客户端的租赁文件中提供名称。
如果你的主机是一个Internet网关,它通常会提供一个本地静态地址。 提供Internet网关地址可能会导致路由和防火墙问题。
你可以configuration你的DHCP客户端写一行主机文件。 除了/etc/hosts之外,还可以使用dnsmasq选项addn-host来获取dnsmasq来读取此文件。 如果地址可能改变,那么DHCP客户端可以重写该文件,并发送dnsmasq作为IP地址改变的HUP信号。
dnsmasq可以通过禁止从/ etc / hosts读取并configuration另一个configuration文件来读取主机名(包括自己)来parsing自己的主机名。
dnsmasqconfiguration(/etc/dnsmaq.conf):
no-hosts addn-hosts=/etc/dnsmasq_hosts
在/ etc / dnsmasq_hosts中,configuration自己的主机名指向需要的IP地址(以及本地局域网中的其他主机名)。