systemd-networkd refuses to apply route with gateway out of the NIC's subnet
| Affects | Status | Importance | Assigned to | Milestone | |
|---|---|---|---|---|---|
| cloud-init (Ubuntu) |
Invalid
|
Undecided
|
Unassigned | ||
| Focal |
Confirmed
|
Undecided
|
Unassigned | ||
| netplan.io (Ubuntu) |
Invalid
|
Undecided
|
Unassigned | ||
| Focal |
Confirmed
|
Undecided
|
Unassigned | ||
| systemd (Ubuntu) |
Confirmed
|
Undecided
|
Unassigned | ||
| Focal |
Confirmed
|
Undecided
|
Unassigned | ||
Bug Description
The version of systemd-networkd on Ubuntu Focal refuses to configure a route due to the fact that the address of the gateway is outside of the subnet of the NIC. The onlink option is required. This does not happen on Jammy and Noble.
Steps to reproduce:
```
# ip a
2: ens2: <BROADCAST,
link/ether de:00:00:62:c5:e9 brd ff:ff:ff:ff:ff:ff
inet 212.47.xxx.xxx/32 scope global dynamic ens2
valid_lft 800sec preferred_lft 800sec
inet6 2001:xxx:
valid_lft forever preferred_lft forever
inet6 fe80::dc00:
valid_lft forever preferred_lft forever
# cat /etc/netplan/
version: 2
ethernets:
ens2:
addresses:
- 2001:xxx:
dhcp4: true
routes:
- to: 169.254.42.42/32
via: 62.210.0.1
- to: ::/0
via: fe80::dc00:
# netplan apply
# journalctl -b -u systemd-networkd
...
Jul 18 10:05:59 focal systemd-
...
```
Is this something that netplan fixes and presents it in a better way to networkd in newer versions? Or is this something that networkd improves in newer versions?
cloud-init's upstream bug: https:/
| Changed in cloud-init (Ubuntu): | |
| status: | New → Invalid |

This sounds like it needs a backported feature for systemd-networkd in Focal, i.e. something that got fixed in networkd.
Did you try adding the "on-link: true" setting to your static routes in the Netplan configuration? That might be able to work around the issue.