Persistent route

    • Official Post

    I'd create a system.d service in /storage/.config/system.d to run the "route add" commands as systemd allows you to add dependencies to accurately sequence when things will occur, e.g. after network-online.target but before kodi.service (assuming the routes are needed for Kodi things).

  • I'd create a system.d service in /storage/.config/system.d to run the "route add" commands as systemd allows you to add dependencies to accurately sequence when things will occur, e.g. after network-online.target but before kodi.service (assuming the routes are needed for Kodi things).

    It works.

    Thanks

  • I'd create a system.d service in /storage/.config/system.d to run the "route add" commands as systemd allows you to add dependencies to accurately sequence when things will occur, e.g. after network-online.target but before kodi.service (assuming the routes are needed for Kodi things).

    Can you give me the correct ExecStart command in system.d, please ?
    Thanks.

  • Hi

    I'm attempting to add a persistent route using the method described and it's not working for me.

    Running LibreElec 11.0.1 on an Pi 4, I've created a file in /storage/.config/system.d called add-route.service with the following;


    Code
    [Unit]
    Description=Add network routes
    After=network-online.target
    
    [Service]
    ExecStart=sh -c 'ip route add 192.168.1.0/24 via 192.168.0.10'


    when I reboot the box the route is not added.

    Am I missing a step?

  • Thanks chewitt

    Good catch on the full path.

    I've made the change but the route still isn't being added at boot.

    As a test, I've run systemctl start add-routes.service and that successfully adds the route. Is it possible that system.d isn't calling services from the directory at boot?

  • Thanks again chewitt

    issuing the command produced an error. The OS wanted an [Install] section added to the file. I added the section with a WantedBy directive and arbitrary picked kodi.target for the value.

    Once it was added it I ran the 'systemctl enable /storage/.config/system.d/add-route.service' command again which worked and upon reboot the route is added. :)

    Thanks for the help! :thumbup:

    My file add-route.service looks like this:


    Code
    [Unit]
    Description=Add network routes
    After=network-online.target
    Wants=network-online-target
    
    [Service]
    ExecStart=/bin/sh -c 'ip route add 192.168.1.0/24 via 192.168.0.10'
    
    [Install]
    WantedBy=kodi.target