brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: netplan routing-policy sends replies out the interface they came in on

Netplan
~/tips/tip-netplan-routing-policy

- to: 192.168.3.0/24

With two network cards on different subnets, source-based rules keep the replies on the right card.

A server with two network interfaces and one default gateway has a classic problem: a request that arrives on the second card gets its answer sent out through the first. Netplan can describe the fix in YAML, with routing-policy and a separate routing table.

network:
  version: 2
  ethernets:
    ens3:
      addresses: [192.168.3.30/24]
      routes:
        - to: 192.168.3.0/24
          via: 192.168.3.1
          table: 101
      routing-policy:
        - from: 192.168.3.0/24
          table: 101
          priority: 100

The routes with table: 101 go into their own routing table. The routing-policy entry says that traffic coming from that subnet should use table 101. A second interface gets the same treatment with its own table number, which is how the netplan examples handle two interfaces on different subnets (they use 101 and 102).

The keys are small. from and to match addresses, table must be a positive integer, mark matches traffic marked by iptables, and type-of-service matches by that number. Lower priority numbers are processed first.

The caveat: the docs strongly recommend an explicit, unique priority for every policy rule, and it is mandatory when NetworkManager is the renderer. That is why I added one above even though the plain networkd example does without. Run sudo netplan try instead of apply when you do this over SSH, since a wrong rule can cut your own connection.

Further reading: Netplan YAML reference, Netplan examples

More Netplan tips hidden: true lacp-rate: fast link-local: [] wakeonlan: true ls -l /etc/netplan/ All Netplan tips (21) All topics

Link