System removes custom routes after suspend and resume.

When I add a route

ip route add via

It is removed after suspend and resume. This is annyoing, because it e.g. removes host routes from openvpn, which renders the vpn connection unusable afterwards.

I did confirm the bug in debian and ubuntu and in debian I confirmed that it does not happen with sysvinit.

What do I need to configure, such that systemd does not touch the routing table at all?
I have some scripts which do quite a bit of network configuration and would like that no other part of the system changes the configuration.

  • If you've confirmed that it's a bug, why even assume it can be configured away? Most bugs need bugfixes. – grawity Sep 30 '18 at 11:27
  • Before confrming a bug, I need to know if it isn't just a configuration issue. I would not believe, that nobody noticed that systemd in a default configuration removes routes, so it probably is no bug, but something you can configure. I at least hope so. – allo Oct 1 '18 at 9:18

Welcome to the wonders of systemd. As far as I know, you cannot have systemd ignore the routing. As far as I know, it does so explicitly (ie feature, not bug). However, you can run scripts at sleep/resume time. See man systemd-suspend.service foe details.

Basically, you put a script in /usr/lib/systemd/system-sleep/, that does the following:

if [ "$1" = "post" ] ; then
    ip route add via
    # or call the script that already creates the routing table

Note: the directory might be /lib/systemd/system-sleep/ (without /usr)

  • You assume that all systemd features live in a single program. The service manager doesn't touch networking; the systemd-networkd network manager does – that is, if OP chose to enable and use it. – grawity Sep 30 '18 at 11:56
  • No, I was refering to systemd as the whole suite, not as the single instance of the daemon. – Ljm Dullaart Sep 30 '18 at 13:26
  • It works as workaround, but I need to put a sleep before the vpn restart command. sleep 3 works for me, but probably it depends on the system and how slow or fast systemd reconfigures network related stuff after resume. – allo Oct 3 '18 at 10:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.