这是关于如何提供全部的本地家庭网络解决方案——
- 我发现这里有一个好关于
dnsmasq
配置。 - 我设法利用以上文章为本地家庭网络设置
dnsmasq
服务器,并且我也使用同一台服务器作为 DHCP 服务器。它在服务器本身内运行良好。 - 但是,同一本地家庭网络内的其他笔记本电脑无法对本地机器进行 DNS 查询。
也就是说,dnsmasq
即使我已禁用路由器中的 DNS 服务,安装在这些 Ubuntu 笔记本电脑上的软件也无法从我的 DNS 服务器执行 LAN DNS 查询。也就是说,所有 DNS 服务都应该由我的 DNS 服务器提供。所有这些 Ubuntu 笔记本电脑都包含nameserver 127.0.1.1
该/etc/resolv.conf
文件,该文件反过来应该缓存来自我的 DNS 服务器的 DNS 解析,对吗?
更新2:
事实证明,是(Ubuntu 笔记本电脑的)NetworkManager 导致它们的127.0.1.1
名称服务器设置奇怪。以下是 dhclient 更新 DHCP 的日志:
Oct 5 21:07:27 mylptp NetworkManager[854]: <info> [1507252047.0729] manager: NetworkManager state is now DISCONNECTED
Oct 5 21:07:42 mylptp NetworkManager[854]: <info> [1507252062.9239] device (eth0): Activation: starting connection 'Wired connection 1' (daa2...b460)
Oct 5 21:07:42 mylptp NetworkManager[854]: <info> [1507252062.9241] audit: op="connection-activate" uuid="daa2...b460" name="Wired connection 1" pid=4822 uid=0 result="success"
Oct 5 21:07:42 mylptp NetworkManager[854]: <info> [1507252062.9243] device (eth0): state change: disconnected -> prepare (reason 'none') [30 40 0]
Oct 5 21:07:42 mylptp NetworkManager[854]: <info> [1507252062.9245] manager: NetworkManager state is now CONNECTING
Oct 5 21:07:42 mylptp NetworkManager[854]: <info> [1507252062.9253] device (eth0): state change: prepare -> config (reason 'none') [40 50 0]
Oct 5 21:07:42 mylptp NetworkManager[854]: <info> [1507252062.9266] device (eth0): state change: config -> ip-config (reason 'none') [50 70 0]
Oct 5 21:07:42 mylptp NetworkManager[854]: <info> [1507252062.9270] dhcp4 (eth0): activation: beginning transaction (timeout in 45 seconds)
Oct 5 21:07:42 mylptp NetworkManager[854]: <info> [1507252062.9299] dhcp4 (eth0): dhclient started with pid 4826
Oct 5 21:07:42 mylptp dhclient[4826]: DHCPREQUEST of 192.168.2.126 on eth0 to 255.255.255.255 port 67 (xid=0x71e88c46)
Oct 5 21:07:42 mylptp dhclient[4826]: DHCPACK of 192.168.2.126 from 192.168.2.102
Oct 5 21:07:42 mylptp NetworkManager[854]: <info> [1507252062.9619] dhcp4 (eth0): address 192.168.2.126
Oct 5 21:07:42 mylptp NetworkManager[854]: <info> [1507252062.9620] dhcp4 (eth0): plen 24 (255.255.255.0)
Oct 5 21:07:42 mylptp NetworkManager[854]: <info> [1507252062.9620] dhcp4 (eth0): gateway 192.168.2.1
Oct 5 21:07:42 mylptp NetworkManager[854]: <info> [1507252062.9620] dhcp4 (eth0): server identifier 192.168.2.102
Oct 5 21:07:42 mylptp NetworkManager[854]: <info> [1507252062.9620] dhcp4 (eth0): lease time 4294967295
Oct 5 21:07:42 mylptp avahi-daemon[799]: Joining mDNS multicast group on interface eth0.IPv4 with address 192.168.2.126.
Oct 5 21:07:42 mylptp NetworkManager[854]: <info> [1507252062.9620] dhcp4 (eth0): hostname 'mylptp'
Oct 5 21:07:42 mylptp avahi-daemon[799]: New relevant interface eth0.IPv4 for mDNS.
Oct 5 21:07:42 mylptp NetworkManager[854]: <info> [1507252062.9620] dhcp4 (eth0): nameserver '192.168.2.102'
Oct 5 21:07:42 mylptp avahi-daemon[799]: Registering new address record for 192.168.2.126 on eth0.IPv4.
Oct 5 21:07:42 mylptp NetworkManager[854]: <info> [1507252062.9620] dhcp4 (eth0): domain name 'my.domain.name'
Oct 5 21:07:42 mylptp NetworkManager[854]: <info> [1507252062.9621] dhcp4 (eth0): state changed unknown -> bound
Oct 5 21:07:42 mylptp NetworkManager[854]: <info> [1507252062.9630] device (eth0): state change: ip-config -> ip-check (reason 'none') [70 80 0]
Oct 5 21:07:42 mylptp NetworkManager[854]: <info> [1507252062.9635] device (eth0): state change: ip-check -> secondaries (reason 'none') [80 90 0]
Oct 5 21:07:42 mylptp NetworkManager[854]: <info> [1507252062.9637] device (eth0): state change: secondaries -> activated (reason 'none') [90 100 0]
Oct 5 21:07:42 mylptp NetworkManager[854]: <info> [1507252062.9638] manager: NetworkManager state is now CONNECTED_LOCAL
Oct 5 21:07:43 mylptp NetworkManager[854]: <info> [1507252063.0394] manager: NetworkManager state is now CONNECTED_GLOBAL
Oct 5 21:07:43 mylptp NetworkManager[854]: <info> [1507252063.0395] policy: set 'Wired connection 1' (eth0) as default for IPv4 routing and DNS
Oct 5 21:07:43 mylptp NetworkManager[854]: <info> [1507252063.0403] device (eth0): Activation: successful, device activated.
Oct 5 21:10:43 mylptp systemd-resolved[1009]: Switching to DNS server 192.168.2.102 for interface eth0.
Oct 5 21:10:43 mylptp systemd-resolved[1009]: Using degraded feature set (TCP) for DNS server 127.0.1.1.
Oct 5 21:10:43 mylptp systemd-resolved[1009]: Using degraded feature set (UDP) for DNS server 127.0.1.1.
Oct 5 21:10:43 mylptp systemd-resolved[1009]: Using degraded feature set (TCP) for DNS server 127.0.1.1.
Oct 5 21:10:43 mylptp systemd-resolved[1009]: Using degraded feature set (UDP) for DNS server 127.0.1.1.
Oct 5 21:10:43 mylptp systemd-resolved[1009]: Using degraded feature set (TCP) for DNS server 127.0.1.1.
Oct 5 21:10:43 mylptp systemd-resolved[1009]: Using degraded feature set (UDP) for DNS server 127.0.1.1.
为了清晰起见,我将长日志分成几组。从日志中我们可以清楚地看到, 一直dnsmasq
在 DHCP 回复中推送 DNS 服务器的正确 IP 地址(第 3 组,最后一行)。但是,NetworkManager(或systemd-resolved
)出现了故障(第 6 组,第一行)。
为什么 NetworkManager/systemd-resolved 没有使用指示的正确 DNS 服务器?我的笔记本电脑使用/查询本地 DNS 服务器没有问题:
me@mylptp$ dig @192.168.2.102 coral
...
;; ANSWER SECTION:
coral. 0 IN A 192.168.2.102
;; Query time: 0 msec
;; SERVER: 192.168.2.102#53(192.168.2.102)
;; WHEN: Thu Oct 05 21:16:22 EDT 2017
;; MSG SIZE rcvd: 50
我的所有机器都属于:
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 17.04
Release: 17.04
Codename: zesty
$ ls -l /etc/resolv.conf
lrwxrwxrwx 1 root root 35 2017-10-05 21:07 /etc/resolv.conf -> /var/run/NetworkManager/resolv.conf
请帮忙。
更新1:
我缺少的是“应该在 DHCP 回复中推送 DNS/DHCP 服务器的正确 IP 地址“,感谢 dirkt 的指导。但是,我该如何使用 做到这一点dnsmasq
?我访问过以下网址,但没有一个能给我答案:
- https://blogging.dragon.org.uk/howto-setup-dnsmasq-as-dns-dhcp/
- http://xmodulo.com/如何使用-dnsmasq 设置 dhcp 服务器.html
- https://wiki.debian.org/HowTo/dnsmasq
- https://wiki.archlinux.org/index.php/dnsmasq
谢谢。