在netplan中复制一组ip命令

Col*_*ers 10 routing netplan 18.04

我最近从16.04升级到Ubuntu 18.04和我试图找出如何让我ip routeip rule命令,我习惯把中/etc/network/interfaces下netplan工作。

这些是我试图重现的命令,我以前运行过/etc/network/interfaces

sudo ip rule add table 129 from 192.168.1.160
sudo ip route add table 129 to 204.8.230.0/24 dev enp0s3
sudo ip route add table 129 to 192.168.1.0/24 dev enp0s3
sudo ip route add table 129 default via 192.168.1.1
Run Code Online (Sandbox Code Playgroud)

这是我第一次通过 netplan 配置/etc/netplan/01-netcfg.yaml

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: yes
      routes:
        - from: 192.168.1.160
          to: 204.8.230.0/24
          via: 192.168.1.1
        - from: 192.168.1.160
          to: 192.168.1.0/24
          via: 192.168.1.1
Run Code Online (Sandbox Code Playgroud)

但是,重新启动后,这些路由不会显示在ip route输出中。我如何让这些路线坚持下去?

请注意,我还尝试/usr/lib/networkd-dispatcher/routable.d根据我找到的一些文档将这些命令放入脚本中,但这似乎也不起作用。

编辑:我越来越近了。这是新的配置,但现在的问题是,虽然该表显示在 中ip rule,但它ip route show table 129是空的:

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: yes
      routing-policy:
        - from: 192.168.1.160
          table: 129
      routes:
        - to: 204.8.230.0/24
          via: 192.168.1.1
          table: 129
        - to: 192.168.1.0/24
          via: 192.168.1.1
          table: 129
        - to: 0.0.0.0/0
          via: 192.168.1.1
          table: 129
Run Code Online (Sandbox Code Playgroud)

我在 netplan 版本 0.36.1

Col*_*ers 14

我想到了。问题是 systemd-networkd 试图在网络启动之前设置路由,但失败了。修复是on-link: True在路线上:

# This file describes the network interfaces available on your system
# For more information, see netplan(5).
network:
  version: 2
  renderer: networkd
  ethernets:
    enp0s3:
      dhcp4: yes
      routing-policy:
        - from: 192.168.1.160
          table: 129
      routes:
        - to: 204.8.230.0/24
          via: 192.168.1.1
          table: 129
          on-link: True
        - to: 192.168.1.0/24
          via: 192.168.1.1
          table: 129
          on-link: True
        - to: 0.0.0.0/0
          via: 192.168.1.1
          table: 129
          on-link: True
Run Code Online (Sandbox Code Playgroud)