How to set an additional route on the same gateway with systemd-networkd

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite
1












Due to some network peculiarities involving VPNs and conflicting IP ranges, I have two subnets routing to two different interfaces. I would like to make one IP address in one subnet go out via a different gateway.



I can accomplish this by running:



$ route add -host 1.2.3.4 gw 5.6.7.8
$ ip route show
1.2.3.4 via 5.6.7.8 dev eth0 scope link


I would like to make this change permanent. As I'm using systemd-networkd, I am trying to do this by updating the existing /etc/systemd/network/50-dhcp.conf:



[Match]
Name=eth0

[Network]
DHCP=ipv4

[Route]
#Gateway=5.6.7.8
Destination=1.2.3.4/32


This works, but without the Gateway line it doesn't set the route:



$ ip route show
1.2.3.4 dev eth0 proto static scope link


If I uncomment the Gateway line then the new route does not appear at all!



How can I specify a gateway when adding the static route using systemd-networkd?










share|improve this question

























    up vote
    0
    down vote

    favorite
    1












    Due to some network peculiarities involving VPNs and conflicting IP ranges, I have two subnets routing to two different interfaces. I would like to make one IP address in one subnet go out via a different gateway.



    I can accomplish this by running:



    $ route add -host 1.2.3.4 gw 5.6.7.8
    $ ip route show
    1.2.3.4 via 5.6.7.8 dev eth0 scope link


    I would like to make this change permanent. As I'm using systemd-networkd, I am trying to do this by updating the existing /etc/systemd/network/50-dhcp.conf:



    [Match]
    Name=eth0

    [Network]
    DHCP=ipv4

    [Route]
    #Gateway=5.6.7.8
    Destination=1.2.3.4/32


    This works, but without the Gateway line it doesn't set the route:



    $ ip route show
    1.2.3.4 dev eth0 proto static scope link


    If I uncomment the Gateway line then the new route does not appear at all!



    How can I specify a gateway when adding the static route using systemd-networkd?










    share|improve this question























      up vote
      0
      down vote

      favorite
      1









      up vote
      0
      down vote

      favorite
      1






      1





      Due to some network peculiarities involving VPNs and conflicting IP ranges, I have two subnets routing to two different interfaces. I would like to make one IP address in one subnet go out via a different gateway.



      I can accomplish this by running:



      $ route add -host 1.2.3.4 gw 5.6.7.8
      $ ip route show
      1.2.3.4 via 5.6.7.8 dev eth0 scope link


      I would like to make this change permanent. As I'm using systemd-networkd, I am trying to do this by updating the existing /etc/systemd/network/50-dhcp.conf:



      [Match]
      Name=eth0

      [Network]
      DHCP=ipv4

      [Route]
      #Gateway=5.6.7.8
      Destination=1.2.3.4/32


      This works, but without the Gateway line it doesn't set the route:



      $ ip route show
      1.2.3.4 dev eth0 proto static scope link


      If I uncomment the Gateway line then the new route does not appear at all!



      How can I specify a gateway when adding the static route using systemd-networkd?










      share|improve this question













      Due to some network peculiarities involving VPNs and conflicting IP ranges, I have two subnets routing to two different interfaces. I would like to make one IP address in one subnet go out via a different gateway.



      I can accomplish this by running:



      $ route add -host 1.2.3.4 gw 5.6.7.8
      $ ip route show
      1.2.3.4 via 5.6.7.8 dev eth0 scope link


      I would like to make this change permanent. As I'm using systemd-networkd, I am trying to do this by updating the existing /etc/systemd/network/50-dhcp.conf:



      [Match]
      Name=eth0

      [Network]
      DHCP=ipv4

      [Route]
      #Gateway=5.6.7.8
      Destination=1.2.3.4/32


      This works, but without the Gateway line it doesn't set the route:



      $ ip route show
      1.2.3.4 dev eth0 proto static scope link


      If I uncomment the Gateway line then the new route does not appear at all!



      How can I specify a gateway when adding the static route using systemd-networkd?







      route systemd-networkd






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 7 at 7:00









      Malvineous

      1,78511433




      1,78511433




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          -1
          down vote













          You should look at this post:



          What is the best way to add a permanent route?



          It explains how you should:




          1. Create a named routing table, in the case below the routing table is called "mgmt" and gets the number "200".



            echo '200 mgmt' >> /etc/iproute2/rt_tables



            • Originally the /etc/iproute2/rt_tables file looks like this, with some reserved numbers:



              #
              # reserved values
              #
              255 local
              254 main
              253 default
              0 unspec
              #
              # local
              #




          2. The post goes on specifying how to add the routes:




            Below, a Debian 7/8 interfaces file defines eth0 and eth1. eth1 is the 172 network. eth0 could use DHCP as well. 172.16.100.10 is the IP address to assign to eth1. 172.16.100.1 is the IP address of the router.




            source /etc/network/interfaces.d/*

            # The loopback network interface
            auto lo
            iface lo inet loopback

            # The production network interface
            auto eth0
            allow-hotplug eth0
            # iface eth0 inet dhcp
            # Remove the stanzas below if using DHCP.
            iface eth0 inet static
            address 10.10.10.140
            netmask 255.255.255.0
            gateway 10.10.10.1

            # The management network interface
            auto eth1
            allow-hotplug eth1
            iface eth1 inet static
            address 172.16.100.10
            netmask 255.255.255.0
            post-up ip route add 172.16.100.0/24 dev eth1 src 172.16.100.1 table mgmt
            post-up ip route add default via 172.16.100.1 dev eth1 table mgmt
            post-up ip rule add from 172.16.100.10/32 table mgmt
            post-up ip rule add to 172.16.100.10/32 table mgmt



          Reboot or restart networking.




          Thanx to user Christopher for this answer.






          share|improve this answer




















          • Unfortunately this answer only applies to Debian, which I'm not using, so /etc/network doesn't exist on my system. I am using systemd-networkd instead of the Debian network manager, so I'm after a solution that works with systemd. Maybe you could update your answer with a systemd solution instead of a Debian-only solution?
            – Malvineous
            Aug 9 at 1:08










          • Check out the link I posted in the answer.
            – aliex
            Aug 17 at 10:34










          • The link still only explains for Debian and RHEL, it does not mention systemd-networkd at all!
            – Malvineous
            Aug 20 at 3:52










          Your Answer







          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "106"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f460978%2fhow-to-set-an-additional-route-on-the-same-gateway-with-systemd-networkd%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          -1
          down vote













          You should look at this post:



          What is the best way to add a permanent route?



          It explains how you should:




          1. Create a named routing table, in the case below the routing table is called "mgmt" and gets the number "200".



            echo '200 mgmt' >> /etc/iproute2/rt_tables



            • Originally the /etc/iproute2/rt_tables file looks like this, with some reserved numbers:



              #
              # reserved values
              #
              255 local
              254 main
              253 default
              0 unspec
              #
              # local
              #




          2. The post goes on specifying how to add the routes:




            Below, a Debian 7/8 interfaces file defines eth0 and eth1. eth1 is the 172 network. eth0 could use DHCP as well. 172.16.100.10 is the IP address to assign to eth1. 172.16.100.1 is the IP address of the router.




            source /etc/network/interfaces.d/*

            # The loopback network interface
            auto lo
            iface lo inet loopback

            # The production network interface
            auto eth0
            allow-hotplug eth0
            # iface eth0 inet dhcp
            # Remove the stanzas below if using DHCP.
            iface eth0 inet static
            address 10.10.10.140
            netmask 255.255.255.0
            gateway 10.10.10.1

            # The management network interface
            auto eth1
            allow-hotplug eth1
            iface eth1 inet static
            address 172.16.100.10
            netmask 255.255.255.0
            post-up ip route add 172.16.100.0/24 dev eth1 src 172.16.100.1 table mgmt
            post-up ip route add default via 172.16.100.1 dev eth1 table mgmt
            post-up ip rule add from 172.16.100.10/32 table mgmt
            post-up ip rule add to 172.16.100.10/32 table mgmt



          Reboot or restart networking.




          Thanx to user Christopher for this answer.






          share|improve this answer




















          • Unfortunately this answer only applies to Debian, which I'm not using, so /etc/network doesn't exist on my system. I am using systemd-networkd instead of the Debian network manager, so I'm after a solution that works with systemd. Maybe you could update your answer with a systemd solution instead of a Debian-only solution?
            – Malvineous
            Aug 9 at 1:08










          • Check out the link I posted in the answer.
            – aliex
            Aug 17 at 10:34










          • The link still only explains for Debian and RHEL, it does not mention systemd-networkd at all!
            – Malvineous
            Aug 20 at 3:52














          up vote
          -1
          down vote













          You should look at this post:



          What is the best way to add a permanent route?



          It explains how you should:




          1. Create a named routing table, in the case below the routing table is called "mgmt" and gets the number "200".



            echo '200 mgmt' >> /etc/iproute2/rt_tables



            • Originally the /etc/iproute2/rt_tables file looks like this, with some reserved numbers:



              #
              # reserved values
              #
              255 local
              254 main
              253 default
              0 unspec
              #
              # local
              #




          2. The post goes on specifying how to add the routes:




            Below, a Debian 7/8 interfaces file defines eth0 and eth1. eth1 is the 172 network. eth0 could use DHCP as well. 172.16.100.10 is the IP address to assign to eth1. 172.16.100.1 is the IP address of the router.




            source /etc/network/interfaces.d/*

            # The loopback network interface
            auto lo
            iface lo inet loopback

            # The production network interface
            auto eth0
            allow-hotplug eth0
            # iface eth0 inet dhcp
            # Remove the stanzas below if using DHCP.
            iface eth0 inet static
            address 10.10.10.140
            netmask 255.255.255.0
            gateway 10.10.10.1

            # The management network interface
            auto eth1
            allow-hotplug eth1
            iface eth1 inet static
            address 172.16.100.10
            netmask 255.255.255.0
            post-up ip route add 172.16.100.0/24 dev eth1 src 172.16.100.1 table mgmt
            post-up ip route add default via 172.16.100.1 dev eth1 table mgmt
            post-up ip rule add from 172.16.100.10/32 table mgmt
            post-up ip rule add to 172.16.100.10/32 table mgmt



          Reboot or restart networking.




          Thanx to user Christopher for this answer.






          share|improve this answer




















          • Unfortunately this answer only applies to Debian, which I'm not using, so /etc/network doesn't exist on my system. I am using systemd-networkd instead of the Debian network manager, so I'm after a solution that works with systemd. Maybe you could update your answer with a systemd solution instead of a Debian-only solution?
            – Malvineous
            Aug 9 at 1:08










          • Check out the link I posted in the answer.
            – aliex
            Aug 17 at 10:34










          • The link still only explains for Debian and RHEL, it does not mention systemd-networkd at all!
            – Malvineous
            Aug 20 at 3:52












          up vote
          -1
          down vote










          up vote
          -1
          down vote









          You should look at this post:



          What is the best way to add a permanent route?



          It explains how you should:




          1. Create a named routing table, in the case below the routing table is called "mgmt" and gets the number "200".



            echo '200 mgmt' >> /etc/iproute2/rt_tables



            • Originally the /etc/iproute2/rt_tables file looks like this, with some reserved numbers:



              #
              # reserved values
              #
              255 local
              254 main
              253 default
              0 unspec
              #
              # local
              #




          2. The post goes on specifying how to add the routes:




            Below, a Debian 7/8 interfaces file defines eth0 and eth1. eth1 is the 172 network. eth0 could use DHCP as well. 172.16.100.10 is the IP address to assign to eth1. 172.16.100.1 is the IP address of the router.




            source /etc/network/interfaces.d/*

            # The loopback network interface
            auto lo
            iface lo inet loopback

            # The production network interface
            auto eth0
            allow-hotplug eth0
            # iface eth0 inet dhcp
            # Remove the stanzas below if using DHCP.
            iface eth0 inet static
            address 10.10.10.140
            netmask 255.255.255.0
            gateway 10.10.10.1

            # The management network interface
            auto eth1
            allow-hotplug eth1
            iface eth1 inet static
            address 172.16.100.10
            netmask 255.255.255.0
            post-up ip route add 172.16.100.0/24 dev eth1 src 172.16.100.1 table mgmt
            post-up ip route add default via 172.16.100.1 dev eth1 table mgmt
            post-up ip rule add from 172.16.100.10/32 table mgmt
            post-up ip rule add to 172.16.100.10/32 table mgmt



          Reboot or restart networking.




          Thanx to user Christopher for this answer.






          share|improve this answer












          You should look at this post:



          What is the best way to add a permanent route?



          It explains how you should:




          1. Create a named routing table, in the case below the routing table is called "mgmt" and gets the number "200".



            echo '200 mgmt' >> /etc/iproute2/rt_tables



            • Originally the /etc/iproute2/rt_tables file looks like this, with some reserved numbers:



              #
              # reserved values
              #
              255 local
              254 main
              253 default
              0 unspec
              #
              # local
              #




          2. The post goes on specifying how to add the routes:




            Below, a Debian 7/8 interfaces file defines eth0 and eth1. eth1 is the 172 network. eth0 could use DHCP as well. 172.16.100.10 is the IP address to assign to eth1. 172.16.100.1 is the IP address of the router.




            source /etc/network/interfaces.d/*

            # The loopback network interface
            auto lo
            iface lo inet loopback

            # The production network interface
            auto eth0
            allow-hotplug eth0
            # iface eth0 inet dhcp
            # Remove the stanzas below if using DHCP.
            iface eth0 inet static
            address 10.10.10.140
            netmask 255.255.255.0
            gateway 10.10.10.1

            # The management network interface
            auto eth1
            allow-hotplug eth1
            iface eth1 inet static
            address 172.16.100.10
            netmask 255.255.255.0
            post-up ip route add 172.16.100.0/24 dev eth1 src 172.16.100.1 table mgmt
            post-up ip route add default via 172.16.100.1 dev eth1 table mgmt
            post-up ip rule add from 172.16.100.10/32 table mgmt
            post-up ip rule add to 172.16.100.10/32 table mgmt



          Reboot or restart networking.




          Thanx to user Christopher for this answer.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 7 at 10:00









          aliex

          92




          92











          • Unfortunately this answer only applies to Debian, which I'm not using, so /etc/network doesn't exist on my system. I am using systemd-networkd instead of the Debian network manager, so I'm after a solution that works with systemd. Maybe you could update your answer with a systemd solution instead of a Debian-only solution?
            – Malvineous
            Aug 9 at 1:08










          • Check out the link I posted in the answer.
            – aliex
            Aug 17 at 10:34










          • The link still only explains for Debian and RHEL, it does not mention systemd-networkd at all!
            – Malvineous
            Aug 20 at 3:52
















          • Unfortunately this answer only applies to Debian, which I'm not using, so /etc/network doesn't exist on my system. I am using systemd-networkd instead of the Debian network manager, so I'm after a solution that works with systemd. Maybe you could update your answer with a systemd solution instead of a Debian-only solution?
            – Malvineous
            Aug 9 at 1:08










          • Check out the link I posted in the answer.
            – aliex
            Aug 17 at 10:34










          • The link still only explains for Debian and RHEL, it does not mention systemd-networkd at all!
            – Malvineous
            Aug 20 at 3:52















          Unfortunately this answer only applies to Debian, which I'm not using, so /etc/network doesn't exist on my system. I am using systemd-networkd instead of the Debian network manager, so I'm after a solution that works with systemd. Maybe you could update your answer with a systemd solution instead of a Debian-only solution?
          – Malvineous
          Aug 9 at 1:08




          Unfortunately this answer only applies to Debian, which I'm not using, so /etc/network doesn't exist on my system. I am using systemd-networkd instead of the Debian network manager, so I'm after a solution that works with systemd. Maybe you could update your answer with a systemd solution instead of a Debian-only solution?
          – Malvineous
          Aug 9 at 1:08












          Check out the link I posted in the answer.
          – aliex
          Aug 17 at 10:34




          Check out the link I posted in the answer.
          – aliex
          Aug 17 at 10:34












          The link still only explains for Debian and RHEL, it does not mention systemd-networkd at all!
          – Malvineous
          Aug 20 at 3:52




          The link still only explains for Debian and RHEL, it does not mention systemd-networkd at all!
          – Malvineous
          Aug 20 at 3:52

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f460978%2fhow-to-set-an-additional-route-on-the-same-gateway-with-systemd-networkd%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay