我的dnsmasq配置为:
所有通过DHCP注册的“*.lan”主机都能很好地解析: dnsmasq知道哪些IP分配给哪个主机名。但是,“rtfm.lan”是从/etc/host读取的,解析为127.0.0.1。
我可以阻止dnsmasq阅读/etc/host并手动添加地址:
no-hosts
address=/rtfm.lan/192.168.1.2但是这是不灵活的:如果有一天我决定改变我的IP --我也将不得不在dnsmasq.conf中更改它。
我如何告诉dnsmasq使用本地主机名及其真正的IP?
以防万一。下面是我的DNSmasq配置:
# 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发布于 2011-03-22 21:27:24
通常,您将在/etc/hosts中定义静态主机,并在dnsmasq.conf文件中启用hosts。dnsmasq允许您为该文件指定一个备用名称。
如果您希望rtfm.lan被命名为192.168.1.2,那么在/etc/hosts中添加一行读取192.168.1.2 rtfm.lan。通常,dnsmasq的主机文件应该可移植到所有服务器。
在rtfm.lan上,IP协议栈会短路路由,不会将流量发送到网络上.
如果您用/etc/hosts信号更新您的dnsmasq文件和信号HUP,主机文件将被重新读取并应用更改。
编辑: dnsmasq不是为自己的主机提供动态主机地址。如前所述,它确实为DHCP客户端提供了其租约文件中的名称。
如果您的主机是Internet网关,它通常会提供本地静态地址。提供Internet网关地址可能会导致路由和防火墙问题。
您可以将DHCP客户端配置为编写一行主机文件。dnsmasq选项addn-host可以用来使dnsmasq除/etc/hosts之外读取此文件。如果地址可能会更改,则DHCP客户端可以重写文件,并在IP地址更改时向dnsmasq发送HUP信号。
发布于 2015-03-19 11:05:32
dnsmasq可以通过禁用/etc/host的读取并配置另一个用于读取主机名的配置文件来解析自己的主机名,包括其本身。
dnsmasq配置(/etc/dnsmaq.conf):
no-hosts
addn-hosts=/etc/dnsmasq_hosts在/etc/dnsmasq_host中,将自己的主机名配置为所需的ip地址(以及本地lan中的其他主机名)。
https://serverfault.com/questions/250524
复制相似问题