我花了好几天的时间在这里用 dnsmasq 设置 DNS 和 DHCP,并用 netplan 来尝试新的方式。
WAN-router is on 192.168.0.1 - works fine
LAN-router is on 192.168.1.1 - DHCP works fine, handing out 192.168.1.x addresses as it should. Can ping google.com
Client laptop is on 192.168.1.181 - Gets IP, can ping LAN-router, can ping IP addresses directly (such as 8.8.8.8) but traceroute and DNS does not work
这是我的 dnsmasq 配置:
bogus-priv
strict-order
filterwin2k
expand-hosts
domain=home
no-resolv
listen-address=127.0.0.1
listen-address=192.168.1.1
#DHCP range
dhcp-range=192.168.1.1,192.168.1.254,72h
dhcp-option=option:router,192.168.0.1
# Upstream name servers
server=192.168.0.1
server=8.8.4.4
server=8.8.8.8
dnsmasq 的状态,启动正常:
Nov 15 06:54:17 router systemd[1]: Starting dnsmasq - A lightweight DHCP and caching DNS server...
Nov 15 06:54:17 router dnsmasq[2000]: dnsmasq: syntax check OK.
Nov 15 06:54:17 router dnsmasq[2030]: started, version 2.79 cachesize 150
Nov 15 06:54:17 router dnsmasq[2030]: compile time options: IPv6 GNU-getopt DBus i18n IDN DHCP DHCPv6 no-Lua TFTP conntrack ipset auth DNSSEC loop-detect inotify
Nov 15 06:54:17 router dnsmasq-dhcp[2030]: DHCP, IP range 192.168.1.1 -- 192.168.1.254, lease time 3d
Nov 15 06:54:17 router dnsmasq[2030]: using nameserver 8.8.8.8#53
Nov 15 06:54:17 router dnsmasq[2030]: using nameserver 8.8.4.4#53
Nov 15 06:54:17 router dnsmasq[2030]: using nameserver 192.168.0.1#53
Nov 15 06:54:17 router dnsmasq[2030]: read /etc/hosts - 7 addresses
Nov 15 06:54:17 router systemd[1]: Started dnsmasq - A lightweight DHCP and caching DNS server.
ip地址显示:
2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:e8:4c:68:61:52 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.205/24 brd 192.168.0.255 scope global dynamic enp1s0
valid_lft 1962sec preferred_lft 1962sec
inet6 fe80::2e8:4cff:fe68:6152/64 scope link
valid_lft forever preferred_lft forever
3: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
link/ether 00:e8:4c:68:61:53 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.1/24 brd 192.168.1.255 scope global enp2s0
valid_lft forever preferred_lft forever
inet6 fe80::2e8:4cff:fe68:6153/64 scope link
valid_lft forever preferred_lft forever
netplan-yaml:
network:
renderer: networkd
ethernets:
enp1s0:
addresses: []
dhcp4: true
enp2s0:
addresses: [192.168.1.1/24]
gateway4: 192.168.0.1
dhcp4: false
nameservers:
search: [home]
addresses: [192.168.0.1,8.8.8.8,8.8.4.4]
version: 2
我确信我一路上搞混了。我能够通过 DNS 解析客户端笔记本电脑上的名称一段时间,但无法进行实际的数据传输,因此实际上无法真正连接到互联网。
这对我来说有点新,所以很感激任何指点。
答案1
这实际上不是 netplan 的问题;您的 dnsmasq 配置中似乎有错误。
据我所知,您的 dnsmasq 配置在连接您的 WAN 和 LAN 接口的 Ubuntu 路由器上运行,并为 LAN 接口提供 DHCP 配置,其中包含以下条目:
dhcp-option=option:router,192.168.0.1
但是,192.168.0.1 不是 LAN 网络上的地址;它是 WAN 网络上的地址(WAN 网关)。因此,告诉 LAN 网络上的 DHCP 客户端将其用作网关是错误的,因为它们没有到该网关的路由。
相反,您应该提供 Ubuntu 路由器的 LAN 地址作为网关:
dhcp-option=option:router,192.168.1.1
您还需要在 Ubuntu 路由器上进行 IP 转发配置:如何使 IP 转发永久化?
此外,您还需要任何一个配置你的 WAN 路由器,使其了解你的 Ubuntu 路由器,并且它是 192.168.1.0/24 网络的网关,或者在你的 Ubuntu 路由器上配置 NAT:在 Ubuntu 12.04 中配置 Nat