Ubuntu
Ubuntu:netplan 禁用 dhcp
系統 ip 配置 b4 netplan 編輯:
root@pro-rpi-02:/# ip a sh 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether dc:a6:32:b3:45:e0 brd ff:ff:ff:ff:ff:ff inet 192.168.1.2/26 brd 192.168.1.63 scope global eth0 valid_lft forever preferred_lft forever inet 192.168.1.7/26 brd 192.168.1.63 scope global secondary eth0 valid_lft forever preferred_lft forever inet6 fe80::4569:7d7a:108d:c2ad/64 scope link valid_lft forever preferred_lft forever
我在 netplan 中添加了一個 vlan:
root@pro-rpi-02:/# more /etc/netplan/01-netcfg.yaml network: version: 2 renderer: networkd ethernets: eth0: dhcp4: no addresses: - 192.168.1.2/26 gateway4: 192.168.1.10 nameservers: addresses: [192.168.1.24] search: [hello.home] vlans: vlan.8: id: 8 link: eth0 dhcp4: no addresses: - 192.168.8.2/24
現在有趣的部分:
root@pro-rpi-02:/cluster/Radius# ip addr sh 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000 link/ether dc:a6:32:b3:45:e0 brd ff:ff:ff:ff:ff:ff inet 192.168.1.2/26 brd 192.168.1.63 scope global eth0 valid_lft forever preferred_lft forever inet 192.168.1.5/26 brd 192.168.1.63 scope global secondary eth0 valid_lft forever preferred_lft forever inet6 fe80::4569:7d7a:108d:c2ad/64 scope link valid_lft forever preferred_lft forever 3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN group default qlen 1000 link/ether dc:a6:32:b3:45:e1 brd ff:ff:ff:ff:ff:ff 4: vlan.8@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether dc:a6:32:b3:45:e0 brd ff:ff:ff:ff:ff:ff inet 192.168.8.2/24 brd 192.168.8.255 scope global vlan.8 valid_lft forever preferred_lft forever inet 192.168.8.112/24 brd 192.168.8.255 scope global secondary noprefixroute vlan.8 valid_lft forever preferred_lft forever
任何人都可以解釋為什麼我得到 dhcp 地址 192.168.8.112/24 ?或者至少讓我知道我可以從哪裡開始尋找?
root@pro-rpi-02:/# netplan --debug generate DEBUG:command generate: running ['/lib/netplan/generate'] ** (generate:750570): DEBUG: 12:17:28.037: Processing input file /etc/netplan/01-netcfg.yaml.. ** (generate:750570): DEBUG: 12:17:28.038: starting new processing pass ** (generate:750570): DEBUG: 12:17:28.038: We have some netdefs, pass them through a final round of validation ** (generate:750570): DEBUG: 12:17:28.038: eth0: setting default backend to 1 ** (generate:750570): DEBUG: 12:17:28.038: Configuration is valid ** (generate:750570): DEBUG: 12:17:28.038: vlan.8: setting default backend to 1 ** (generate:750570): DEBUG: 12:17:28.039: Configuration is valid ** (generate:750570): DEBUG: 12:17:28.040: Generating output files.. ** (generate:750570): DEBUG: 12:17:28.040: openvswitch: definition eth0 is not for us (backend 1) ** (generate:750570): DEBUG: 12:17:28.040: NetworkManager: definition eth0 is not for us (backend 1) ** (generate:750570): DEBUG: 12:17:28.040: openvswitch: definition vlan.8 is not for us (backend 1) ** (generate:750570): DEBUG: 12:17:28.040: NetworkManager: definition vlan.8 is not for us (backend 1)
UPDATE 1,根據要求,這是輸出,但在這裡看不到任何可以幫助我的東西:)
root@pro-rpi-02:~# networkctl --full --all --no-pager status ● 1: lo Link File: /usr/lib/systemd/network/99-default.link Network File: n/a Type: loopback State: carrier (unmanaged) MTU: 65536 QDisc: noqueue IPv6 Address Generation Mode: eui64 Queue Length (Tx/Rx): 1/1 Address: 127.0.0.1 ● 2: eth0 Link File: /usr/lib/systemd/network/99-default.link Network File: /run/systemd/network/10-netplan-eth0.network Type: ether State: routable (failed) Path: platform-fd580000.ethernet Driver: bcmgenet HW Address: dc:a6:32:b3:45:e0 (Raspberry Pi Trading Ltd) MTU: 1500 (min: 68, max: 1500) QDisc: mq IPv6 Address Generation Mode: eui64 Queue Length (Tx/Rx): 5/5 Auto negotiation: yes Speed: 1Gbps Duplex: full Port: mii Address: 192.168.1.2 192.168.1.5 192.168.1.7 fe80::4569:7d7a:108d:c2ad Gateway: 192.168.1.10 DNS: 192.168.1.24 Search Domains: hello.home DHCP6 Client DUID: DUID-EN/Vendor:0000ab112ca77a819cd16ac00000 Mar 10 22:03:14 pro-rpi-02 systemd-networkd[926]: eth0: IPv6 successfully enabled Mar 10 22:03:14 pro-rpi-02 systemd-networkd[926]: eth0: Link UP Apr 19 16:51:22 pro-rpi-02 systemd-networkd[926]: eth0: Gained carrier Apr 19 16:51:24 pro-rpi-02 systemd-networkd[926]: eth0: Gained IPv6LL Apr 20 16:32:48 pro-rpi-02 systemd-networkd[926]: eth0: DHCPv6 lease lost Apr 20 16:32:48 pro-rpi-02 systemd-networkd[672911]: eth0: Gained IPv6LL Apr 20 16:32:48 pro-rpi-02 systemd-networkd[672911]: eth0: IPv6 successfully enabled Apr 20 16:32:48 pro-rpi-02 systemd-networkd[672911]: eth0: Could not set route: Nexthop has invalid gateway. Network is unreachable Apr 20 16:32:48 pro-rpi-02 systemd-networkd[672911]: eth0: Failed ● 3: wlan0 Link File: /usr/lib/systemd/network/99-default.link Network File: n/a Type: wlan State: no-carrier (unmanaged) Path: platform-fe300000.mmcnr Driver: brcmfmac HW Address: dc:a6:32:b3:45:e1 (Raspberry Pi Trading Ltd) MTU: 1500 (min: 68, max: 1500) QDisc: fq_codel IPv6 Address Generation Mode: none Queue Length (Tx/Rx): 1/1 Apr 19 16:51:22 pro-rpi-02 systemd-networkd[926]: wlan0: Link UP ● 4: vlan8 Link File: /usr/lib/systemd/network/99-default.link Network File: /run/systemd/network/10-netplan-vlan8.network Type: vlan State: routable (configuring) Driver: 802.1Q VLAN Support HW Address: dc:a6:32:b3:45:e0 (Raspberry Pi Trading Ltd) MTU: 1500 (max: 65535) QDisc: noqueue IPv6 Address Generation Mode: eui64 VLan Id: 8 Queue Length (Tx/Rx): 1/1 Auto negotiation: yes Speed: 1Gbps Duplex: full Port: mii Address: 192.168.8.2 192.168.8.112 Gateway: 192.168.8.10 DHCP6 Client DUID: DUID-EN/Vendor:0000ab112ca77a819cd16ac00000 Apr 20 16:32:48 pro-rpi-02 systemd-networkd[672911]: vlan8: netdev ready Apr 20 16:32:49 pro-rpi-02 systemd-networkd[672911]: vlan8: Link UP Apr 20 16:32:49 pro-rpi-02 systemd-networkd[672911]: vlan8: Gained carrier Apr 20 16:32:49 pro-rpi-02 systemd-networkd[672911]: vlan8: IPv6 successfully enabled
在花了 X 小時試圖在這裡找到修復程序後,我決定禁用dhcpcd服務:
root@pro-rpi-02:~# systemctl status dhcpcd.service ● dhcpcd.service - DHCP Client Daemon Loaded: loaded (/lib/systemd/system/dhcpcd.service; disabled; vendor preset: enabled) Active: inactive (dead) Docs: man:dhcpcd(8)
現在一切都像我希望的那樣工作:
root@pro-rpi-02:~# more /etc/netplan/01-netcfg.yaml network: version: 2 renderer: networkd ethernets: eth0: dhcp4: no dhcp6: no addresses: - 192.168.1.2/26 gateway4: 192.168.1.10 nameservers: addresses: [192.168.1.24] search: [hello.home] vlans: vlan8: id: 8 link: eth0 dhcp4: no dhcp6: no addresses: - 192.168.8.2/24 root@pro-rpi-02:~# ip a sh vlan8 4: vlan8@eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000 link/ether dc:a6:32:b3:45:e0 brd ff:ff:ff:ff:ff:ff inet 192.168.8.2/24 brd 192.168.8.255 scope global vlan8 valid_lft forever preferred_lft forever inet6 fe80::dea6:32ff:feb3:45e0/64 scope link valid_lft forever preferred_lft forever