should be possible to specify static routes on a dhcp-configured interface

Bug #1781652 reported by Steve Langasek
52
This bug affects 11 people
Affects Status Importance Assigned to Milestone
Netplan
Confirmed
Low
Unassigned
systemd (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

From <https://askubuntu.com/questions/1054572/netplan-is-there-an-equivalent-to-post-up>, a user wants to add a static route to a network interface where the gateway is known, but the interface's local address is configured via dhcp.

This doesn't work with direct netplan yaml, because networkd will try to apply the static routes before the interface has been configured via dhcp, failing because there is not yet a route to the gateway on that interface.

Demonstrating in a lxd container locally, which has 10.44.49.0/24 as its network:

$ cat /etc/netplan/50-cloud-init.yaml
# This file is generated from information provided by
# the datasource. Changes to it will not persist across an instance.
# To disable cloud-init's network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
    version: 2
    ethernets:
        eth0:
            dhcp4: true
            routes:
               - to: 10.44.48.0/24
                 via: 10.44.49.2
                 metric: 10
$ systemctl status systemd-networkd --no-pager -l
● systemd-networkd.service - Network Service
   Loaded: loaded (/lib/systemd/system/systemd-networkd.service; enabled; vendor preset: enabled)
   Active: active (running) since Fri 2018-07-13 19:21:29 UTC; 8min ago
     Docs: man:systemd-networkd.service(8)
 Main PID: 165 (systemd-network)
   Status: "Processing requests..."
    Tasks: 1 (limit: 4915)
   CGroup: /system.slice/systemd-networkd.service
           └─165 /lib/systemd/systemd-networkd

Jul 13 19:21:29 stable-dane systemd[1]: Starting Network Service...
Jul 13 19:21:29 stable-dane systemd-networkd[165]: Enumeration completed
Jul 13 19:21:29 stable-dane systemd[1]: Started Network Service.
Jul 13 19:21:29 stable-dane systemd-networkd[165]: eth0: Could not set route: Network is unreachable
Jul 13 19:21:29 stable-dane systemd-networkd[165]: eth0: DHCPv4 address 10.44.49.32/24 via 10.44.49.1
Jul 13 19:21:29 stable-dane systemd-networkd[165]: Not connected to system bus, not setting hostname.
Jul 13 19:21:29 stable-dane systemd-networkd[165]: eth0: Gained IPv6LL
Jul 13 19:21:29 stable-dane systemd-networkd[165]: eth0: Configured
Jul 13 19:21:55 stable-dane systemd-networkd[165]: Could not set hostname: Method call timed out
$ ip route
default via 10.44.49.1 dev eth0 proto dhcp src 10.44.49.32 metric 100
10.44.49.0/24 dev eth0 proto kernel scope link src 10.44.49.32
10.44.49.1 dev eth0 proto dhcp scope link src 10.44.49.32 metric 100
$

netplan and networkd should DTRT.

Steve Langasek (vorlon)
Changed in netplan:
importance: Undecided → Low
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in systemd (Ubuntu):
status: New → Confirmed
Revision history for this message
Daniel Axtens (daxtens) wrote :

This hit me too.

I'm not sure how netplan can fix this - it looks like it's generating pretty sensible configuration files.

Changed in netplan:
status: New → Confirmed
status: Confirmed → New
Revision history for this message
Fabien Toral (malibug) wrote :

I've the same problem.

I'm operating 17.10 systems with network initially configured with DHCP. We need to add pemanent static routes and networkd failed with the same error than reported here.

I think I've found the upstream bug in systemd : https://github.com/systemd/systemd/issues/1850

Revision history for this message
Paweł Wojciechowski (felixdpl) wrote :

Adding ONLINK option to netplan is essential.

I have same problem.

systemd has GatewayOnlink option which can be used.
[Route]
Destination=10.1.0.0/16
Gateway=10.5.0.1
GatewayOnlink=true

I have changed Status to Confirmed (this whole case should be changed from Bug to New feature).

Changed in systemd (Ubuntu):
status: Confirmed → Fix Released
Changed in netplan:
status: New → Confirmed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.