Skip to content

Instantly share code, notes, and snippets.

@iquiw
Last active January 17, 2023 13:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iquiw/373a139e4ab773574983293061d979bb to your computer and use it in GitHub Desktop.
Save iquiw/373a139e4ab773574983293061d979bb to your computer and use it in GitHub Desktop.
Only one route is generated from multiple files with different tables and same vlan

netplan version: 0.105-0ubuntu2~22.04.1

Suppose the following 3 files exist in /etc/netplan.

01-netcfg.yaml

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      dhcp4: false
      dhcp6: false
      addresses: [172.17.17.151/20]
      routes:
        - to: default
          via: 172.17.17.1
      nameservers:
        addresses: [4.2.2.1, 4.2.2.2, 208.67.220.220]
  vlans:
    vlan100:
      id: 100
      link: eth0
      addresses: [10.0.0.1/24,10.0.0.2/24]

10-table1.yaml

network:
  version: 2
  vlans:
    vlan100:
      routing-policy:
        - from: 10.0.0.1
          table: 1001
      routes:
        - to: 0.0.0.0/0
          via: 10.0.0.100
          table: 1001

10-table2.yaml

network:
  version: 2
  vlans:
    vlan100:
      routing-policy:
        - from: 10.0.0.2
          table: 1002
      routes:
        - to: 0.0.0.0/0
          via: 10.0.0.200
          table: 1002

Then, netplan apply generates a route for table 1001 only.

network:
  version: 2
  renderer: networkd
  ethernets:
    eth0:
      addresses:
      - "172.17.17.151/20"
      nameservers:
        addresses:
        - 4.2.2.1
        - 4.2.2.2
        - 208.67.220.220
      dhcp4: false
      dhcp6: false
      routes:
      - to: "default"
        via: "172.17.17.1"
  vlans:
    vlan100:
      addresses:
      - "10.0.0.1/24"
      - "10.0.0.2/24"
      routes:
      - table: 1001
        to: "0.0.0.0/0"
        via: "10.0.0.100"
      routing-policy:
      - table: 1001
        from: "10.0.0.1"
      - table: 1002
        from: "10.0.0.2"
      id: 100
      link: "eth0"

Expected network.vlans.vlan100.routes node is as follows.

      routes:
      - table: 1001
        to: "0.0.0.0/0"
        via: "10.0.0.100"
      - table: 1002
        to: "0.0.0.0/0"
        via: "10.0.0.200"

If 10-table1.yaml and 10-table2.yaml are merged to one file like below, network.vlans.vlan100.routes node is generated as expected.

network:
  version: 2
  vlans:
    vlan100:
      routing-policy:
        - from: 10.0.0.1
          table: 1001
        - from: 10.0.0.2
          table: 1002
      routes:
        - to: 0.0.0.0/0
          via: 10.0.0.100
          table: 1001
        - to: 0.0.0.0/0
          via: 10.0.0.200
          table: 1002
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment