ubuntu 18.04 使用 netplan 设置静态路由

ubuntu 18.04 使用 netplan 设置静态路由

尝试在 ubuntu 18.04 上使用 netplan 设置静态路由。我的配置如下

network:
version: 2
renderer: networkd
ethernets:
    eno1:
        dhcp4: no
        dhcp6: no
        addresses:
            - 192.168.10.20/24
        gateway4: 192.168.10.1
        routes:
        - to: 192.168.9.1/24
          via: 192.168.10.2
        nameservers:
            addresses:
            - 192.168.10.3

未设置路由,我在系统日志中收到此消息

eno1: Could not set route: Invalid argument

调试输出是:

root@schoenberg:/etc/netplan# netplan --debug apply
** (generate:2421): DEBUG: 21:04:12.721: Processing input file /etc/netplan/01-netconfig.yaml..
** (generate:2421): DEBUG: 21:04:12.721: starting new processing pass
** (generate:2421): DEBUG: 21:04:12.721: eno1: setting default backend to 1
** (generate:2421): DEBUG: 21:04:12.721: Configuration is valid
** (generate:2421): DEBUG: 21:04:12.721: Generating output files..
** (generate:2421): DEBUG: 21:04:12.721: NetworkManager: definition eno1 is not for us (backend 1)
DEBUG:netplan generated networkd configuration changed, restarting networkd
DEBUG:no netplan generated NM configuration exists
DEBUG:eno1 not found in {}
DEBUG:Merged config:
network:
  bonds: {}
  bridges: {}
  ethernets:
    eno1:
      addresses:
      - 192.168.10.20/24
      dhcp4: false
      dhcp6: false
      gateway4: 192.168.10.1
      nameservers:
        addresses:
        - 192.168.10.3
      routes:
      - to: 192.168.9.1/24
        via: 192.168.10.2
  vlans: {}
  wifis: {}

DEBUG:Skipping non-physical interface: lo
DEBUG:Skipping non-physical interface: enp4s0
DEBUG:device eno1 operstate is up, not changing
DEBUG:Skipping non-physical interface: docker0
DEBUG:{}
DEBUG:netplan triggering .link rules for lo
DEBUG:netplan triggering .link rules for enp4s0
DEBUG:netplan triggering .link rules for eno1
DEBUG:netplan triggering .link rules for docker0
root@schoenberg:/etc/netplan# 

答案1

192.168.9.1/24作为路线的目的地是没有意义的,因此出现无效参数错误。

如果目标地址是单个主机(即),则路由应为主机路由。不应指定192.168.9.1前缀长度/子网掩码(除/32/外)。255.255.255.255

如果期望的目的地是网络,则路由应该具有指定的网络 ID/地址和前缀长度/子网掩码(例如,,,192.168.9.0/24... )。192.168.9.0/23192.168.146.48/28

原因在于,对于网络路由,目的地的大小由长度/掩码表示(而网络 ID/地址表示其“开始”的位置);对于主机路由,大小始终是单个主机,因此长度/掩码是可选的。

相关内容