我正在尝试将我的 Ubuntu Server 20.04 LTS 配置为在其网络配置中使用 DHCP。
网上很多教程都推荐我用下面的设置创建下面的文件...
root@sinj:/home/brlight# cat /etc/netplan/99_config.yaml
network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: true
...并运行以下命令...
root@sinj:/home/brlight# netplan --debug generate
root@sinj:/home/brlight# netplan apply
问题:服务器正在通过 DHCP 获取其设置,但无法访问 Internet。
加:
与同一网络上的其他服务器不同,该服务器似乎无法获取网关设置。
服务器没问题...
[root@ssh_brl ~]# ip route show
default via 10.0.0.1 dev eth0 proto dhcp metric 100
10.0.0.0/24 dev eth0 proto kernel scope link src 10.0.0.6 metric 100
10.2.0.0/24 via 10.0.0.7 dev eth0 proto dhcp metric 100
服务器有问题...
root@sinj:/home/brlight# ip route show
10.0.0.0/24 dev ens3 proto kernel scope link src 10.0.0.17
10.2.0.0/24 via 10.0.0.7 dev ens3 proto dhcp src 10.0.0.17 metric 100
其他信息:
我
root@sinj:/home/brlight# ip route show
10.0.0.0/24 dev ens3 proto kernel scope link src 10.0.0.17
10.2.0.0/24 via 10.0.0.7 dev ens3 proto dhcp src 10.0.0.17 metric 100
二
root@sinj:/home/brlight# lshw -C network
*-network
description: Ethernet controller
product: Virtio network device
vendor: Red Hat, Inc.
physical id: 3
bus info: pci@0000:00:03.0
version: 00
width: 32 bits
clock: 33MHz
capabilities: msix bus_master cap_list rom
configuration: driver=virtio-pci latency=0
resources: irq:11 ioport:c060(size=32) memory:fc056000-fc056fff memory:fc000000-fc03ffff
*-virtio0
description: Ethernet interface
physical id: 0
bus info: virtio@0
logical name: ens3
serial: 52:54:00:6c:ec:1f
capabilities: ethernet physical
configuration: autonegotiation=off broadcast=yes driver=virtio_net driverversion=1.0.0 ip=10.0.0.17 link=yes multicast=yes
三
root@sinj:/home/brlight# networkctl status ens3
● 2: ens3
Link File: /usr/lib/systemd/network/99-default.link
Network File: /run/systemd/network/10-netplan-ens3.network
Type: ether
State: routable (configured)
Path: pci-0000:00:03.0
Driver: virtio_net
Vendor: Red Hat, Inc.
Model: Virtio network device
HW Address: 52:54:00:6c:ec:1f
MTU: 1500 (min: 68, max: 65535)
Queue Length (Tx/Rx): 1/1
Auto negotiation: no
Speed: n/a
Address: 10.0.0.17 (DHCP4)
fe80::5054:ff:fe6c:ec1f
DNS: 10.0.0.1
Mar 06 01:47:12 sinj systemd-networkd[641]: ens3: IPv6 successfully enabled
Mar 06 01:47:12 sinj systemd-networkd[641]: ens3: Link UP
Mar 06 01:47:12 sinj systemd-networkd[641]: ens3: Gained carrier
Mar 06 01:47:12 sinj systemd-networkd[641]: ens3: DHCPv4 address 10.0.0.17/24 via 10.0.0.1
Mar 06 01:47:13 sinj systemd-networkd[641]: ens3: Gained IPv6LL
四
root@sinj:/home/brlight# dig www.google.com
; <<>> DiG 9.16.1-Ubuntu <<>> www.google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 10647
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 65494
;; QUESTION SECTION:
;www.google.com. IN A
;; ANSWER SECTION:
www.google.com. 41 IN A 172.217.30.36
;; Query time: 48 msec
;; SERVER: 127.0.0.53#53(127.0.0.53)
;; WHEN: Sat Mar 06 04:37:04 UTC 2021
;; MSG SIZE rcvd: 59
五
root@sinj:/home/brlight# dhclient -v ens3
Internet Systems Consortium DHCP Client 4.4.1
Copyright 2004-2018 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/
Listening on LPF/ens3/52:54:00:6c:ec:1f
Sending on LPF/ens3/52:54:00:6c:ec:1f
Sending on Socket/fallback
DHCPREQUEST for 10.0.0.17 on ens3 to 255.255.255.255 port 67 (xid=0x601d9dc1)
DHCPACK of 10.0.0.17 from 10.0.0.5 (xid=0xc19d1d60)
RTNETLINK answers: File exists
bound to 10.0.0.17 -- renewal in 933 seconds.
六
root@sinj:/home/brlight# cat /var/lib/dhcp/dhclient.leases
lease {
interface "ens3";
fixed-address 10.0.0.17;
option subnet-mask 255.255.255.0;
option dhcp-lease-time 4000;
option routers 10.0.0.1;
option dhcp-message-type 5;
option dhcp-server-identifier 10.0.0.5;
option domain-name-servers 10.0.0.1;
option dhcp-renewal-time 1000;
option rfc3442-classless-static-routes 24,10,2,0,10,0,0,7;
option dhcp-rebinding-time 2000;
option host-name "sinj";
renew 6 2021/03/06 05:20:33;
rebind 6 2021/03/06 05:38:40;
expire 6 2021/03/06 06:12:00;
}
lease {
interface "ens3";
fixed-address 10.0.0.17;
option subnet-mask 255.255.255.0;
option dhcp-lease-time 4000;
option routers 10.0.0.1;
option dhcp-message-type 5;
option dhcp-server-identifier 10.0.0.5;
option domain-name-servers 10.0.0.1;
option dhcp-renewal-time 1000;
option rfc3442-classless-static-routes 24,10,2,0,10,0,0,7;
option dhcp-rebinding-time 2000;
option host-name "sinj";
renew 6 2021/03/06 18:50:24;
rebind 6 2021/03/06 19:10:57;
expire 6 2021/03/06 19:44:17;
}
七
root@sinj:/home/brlight# ip route
10.0.0.0/24 dev ens3 proto kernel scope link src 10.0.0.17
10.2.0.0/24 via 10.0.0.7 dev ens3
10.2.0.0/24 via 10.0.0.7 dev ens3 proto dhcp src 10.0.0.17 metric 100
[参考:https://ubuntu.com/server/docs/network-configuration,http://manpages.ubuntu.com/manpages/cosmic/man5/netplan.5.html,https://www.krizna。 com/ubuntu/setup-network-ubuntu-18-04/,https://websiteforstudents.com/configure-static-ip-addresses-on-ubuntu-18-04-beta/,https://www.linuxtechi。 com/assign-static-ip-address-ubuntu-20-04-lts/]
抱歉,这比你发布的晚了 8 个月——但我遇到了同样的问题,正在谷歌上搜索,看看其他人是否已经解决了。
几个月前,我正在尝试使用wireguard,并在两所房子之间建立了一个私人VPN——一切都很好,所以我修改了我的DHCP服务器配置,通过isc-dhcp-server将静态路由(到另一所房子)推送出去
这工作正常,除了Ubuntu 18.04 和 20.04 虚拟机现在都不会设置默认路由。
如果您从 DHCP 服务器 conf 中注释掉任何选项 rfc3442-classless-static-routes 选项 ms-classless-static-routes 并重新启动,则 netplan 应用 - 您应该会发现默认路由返回。
与他们重复 - 默认路线消失。
netplan ip 租赁 ens18 - 确实表明它知道默认路由 - 它只是从不配置它。
RFC3442 说:
因为之前它说:
所以 DHCP 客户端正在做正确的事情,而不是设置默认路由 - 因为您使用的是选项 rfc3442-classless-static-routes
解决方案是在默认路由前加上(在您的情况下)0、10、0、0、1,
在我的网络上是:
这意味着默认路由是 172.16.0.1 并且可以通过 172.16.0.250 访问 172.16.4/22 网络
在应用网络计划后的客户端上:
希望这对一直在搜索并可能遇到此答案的其他人有所帮助。