AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1056147
Accepted
Eduardo Lucio
Eduardo Lucio
Asked: 2021-03-07 09:51:48 +0800 CST2021-03-07 09:51:48 +0800 CST 2021-03-07 09:51:48 +0800 CST

netplan - 配置了 DHCP 的网络,但没有互联网

  • 772

我正在尝试将我的 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/]

networking dhcp isc-dhcp netplan dhcp-server
  • 1 1 个回答
  • 2242 Views

1 个回答

  • Voted
  1. Best Answer
    pgregg
    2021-11-29T11:23:09+08:002021-11-29T11:23:09+08:00

    抱歉,这比你发布的晚了 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 服务器管理员应将其 DHCP
    服务器配置为发送路由器选项和无类静态路由
    选项,并应在路由器选项和无类静态路由选项中指定默认路由器
    。

    因为之前它说:

    如果 DHCP 服务器返回无类静态路由选项和路由器选项,则 DHCP 客户端必须忽略路由器选项。

    所以 DHCP 客户端正在做正确的事情,而不是设置默认路由 - 因为您使用的是选项 rfc3442-classless-static-routes

    解决方案是在默认路由前加上(在您的情况下)0、10、0、0、1,

    在我的网络上是:

    option rfc3442-classless-static-routes 0, 172, 16, 0, 1, 22, 172, 16, 4, 172, 16, 0, 250;
    

    这意味着默认路由是 172.16.0.1 并且可以通过 172.16.0.250 访问 172.16.4/22 网络

    在应用网络计划后的客户端上:

    # ip route show
    default via 172.16.0.1 dev ens18 proto dhcp src 172.16.0.220 metric 100
    172.16.0.0/22 dev ens18 proto kernel scope link src 172.16.0.220
    172.16.4.0/22 via 172.16.0.250 dev ens18 proto dhcp src 172.16.0.220 metric 100
    

    希望这对一直在搜索并可能遇到此答案的其他人有所帮助。

    • 2

相关问题

  • 谁能指出我的 802.11n 范围扩展器?

  • 我怎样才能得到一个网站的IP地址?

  • 在一个 LAN 中使用两台 DHCP 服务器

  • 如何在 Linux 下监控每个进程的网络 I/O 使用情况?

  • 为本地网络中的名称解析添加自定义 dns 条目

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve