Ubuntu

無法設置 DHCPv4 路由:Nexthop 的網關無效。網路不可達

  • December 16, 2021

/etc/netplan/00-installer-config.yaml

# This is the network config written by 'subiquity'
network:
 ethernets:
   ens192:
     dhcp4: true
 version: 2

/run/systemd/network/10-netplan-ens192.network

[Match]
Name=ens192

[Network]
DHCP=ipv4
LinkLocalAddressing=ipv6

[DHCP]
RouteMetric=100
UseMTU=true

ip -4 一個

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
   inet 127.0.0.1/8 scope host lo
      valid_lft forever preferred_lft forever
2: ens192: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000
   inet 217.160.244.97/32 scope global dynamic ens192
      valid_lft 39392sec preferred_lft 39392sec

ip -4 路由

default via 10.255.255.1 dev ens192 proto dhcp src 217.160.244.97 metric 100
10.255.255.1 dev ens192 proto dhcp scope link src 217.160.244.97 metric 100

服務系統網路狀態

● systemd-networkd.service - Network Service
    Loaded: loaded (/lib/systemd/system/systemd-networkd.service; enabled; vendor preset: enabled)
    Active: active (running) since Mon 2020-05-11 06:30:58 UTC; 1h 5min ago
TriggeredBy: ● systemd-networkd.socket
      Docs: man:systemd-networkd.service(8)
  Main PID: 928 (systemd-network)
    Status: "Processing requests..."
     Tasks: 1 (limit: 38422)
    Memory: 3.8M
    CGroup: /system.slice/systemd-networkd.service
            └─928 /lib/systemd/systemd-networkd

May 11 06:30:58 local systemd[1]: Starting Network Service...
May 11 06:30:58 local systemd-networkd[928]: Enumeration completed
May 11 06:30:58 local systemd[1]: Started Network Service.
May 11 06:30:58 local systemd-networkd[928]: ens192: IPv6 successfully enabled
May 11 06:30:58 local systemd-networkd[928]: ens192: Link UP
May 11 06:30:58 local systemd-networkd[928]: ens192: Gained carrier
May 11 06:30:58 local systemd-networkd[928]: ens192: DHCPv4 address 217.160.244.97/32 via 10.255.255.1
May 11 06:30:58 local systemd-networkd[928]: ens192: Could not set DHCPv4 route: Nexthop has invalid gateway. Network is unreachable
May 11 06:30:58 local systemd-networkd[928]: ens192: Failed

我不知道如何解決這個問題!幾天前我一直在嘗試解決它,但仍然無法弄清楚。

我發現在文件中添加“critical:true”:/etc/netplan/00-installer-config.yaml 確保介面不會定期關閉(似乎是 IONOS 的問題)。該文件應如下所示:

# This is the network config written by 'subiquity'
network:
 ethernets:
   ens192:
     dhcp4: true
     critical: true
 version: 2

然後執行:

$ sudo netplan generate
$ sudo netplan apply

這應該有助於任何網路失去。

你只需要做UseRoutes=no,但啟動UseGateway=yes。你可以看看我的預設配置。

/etc/systemd/network/default.network

[Match]
Type=!loopback

[Link]
RequiredForOnline=yes

[Network]
DHCP=yes

[DHCPv4]
UseRoutes=no
UseGateway=yes

引用自:https://serverfault.com/questions/1016591