Why are routes set in /etc/network/interfaces not added when the interface comes up?












1















Here is my interfaces file:



auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

auto eth0:0
iface eth0:0 inet static
address 10.20.8.231
netmask 255.255.255.0
gateway 10.20.8.1
up /sbin/route add 1.2.3.4 gw 10.20.8.1
down /sbin/route del 1.2.3.4 gw 10.20.8.1


From the multiple examples I have found online this should add routes when eth0:0 comes up but for some reason I can't get it to work.



When I try to bring up the interface with ifup eth0:0 I get:



RTNETLINK answers: File exists
Failed to bring up eth0:0.


Then, ifconfig shows eth0:0 is up but route -n does not show the new route. In fact it shows the exact same routes I had before. Nothing changed.



Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.20.8.1 0.0.0.0 UG 0 0 0 eth0
10.20.8.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0


This config is to be used on remote systems that can only be accessed via SSH. The whole idea is to keep eth0 set to dhcp as a backup when the site's network is changed (happened twice already) rendering the static ip unaccessible. The problem with this is that SSH (used by built in processes) uses the default route via eth0 and that doesn't work as the firewall (not managed by us) has been set to allow ssh only for the static IP on eth0:0.



Note: In the example above 1.2.3.4 represents our ssh server and I am trying to route traffic via eth0:0 for that single host but after testing I may want to set the default route to use eth0:0 instead, but I also tried that and it failed the same way. I was using this line:



up route add -net 0.0.0.0 netmask 0.0.0.0 gw 10.20.8.1





Thank you for your assistance.










share|improve this question





























    1















    Here is my interfaces file:



    auto lo
    iface lo inet loopback

    auto eth0
    iface eth0 inet dhcp

    auto eth0:0
    iface eth0:0 inet static
    address 10.20.8.231
    netmask 255.255.255.0
    gateway 10.20.8.1
    up /sbin/route add 1.2.3.4 gw 10.20.8.1
    down /sbin/route del 1.2.3.4 gw 10.20.8.1


    From the multiple examples I have found online this should add routes when eth0:0 comes up but for some reason I can't get it to work.



    When I try to bring up the interface with ifup eth0:0 I get:



    RTNETLINK answers: File exists
    Failed to bring up eth0:0.


    Then, ifconfig shows eth0:0 is up but route -n does not show the new route. In fact it shows the exact same routes I had before. Nothing changed.



    Kernel IP routing table
    Destination Gateway Genmask Flags Metric Ref Use Iface
    0.0.0.0 10.20.8.1 0.0.0.0 UG 0 0 0 eth0
    10.20.8.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0


    This config is to be used on remote systems that can only be accessed via SSH. The whole idea is to keep eth0 set to dhcp as a backup when the site's network is changed (happened twice already) rendering the static ip unaccessible. The problem with this is that SSH (used by built in processes) uses the default route via eth0 and that doesn't work as the firewall (not managed by us) has been set to allow ssh only for the static IP on eth0:0.



    Note: In the example above 1.2.3.4 represents our ssh server and I am trying to route traffic via eth0:0 for that single host but after testing I may want to set the default route to use eth0:0 instead, but I also tried that and it failed the same way. I was using this line:



    up route add -net 0.0.0.0 netmask 0.0.0.0 gw 10.20.8.1





    Thank you for your assistance.










    share|improve this question



























      1












      1








      1








      Here is my interfaces file:



      auto lo
      iface lo inet loopback

      auto eth0
      iface eth0 inet dhcp

      auto eth0:0
      iface eth0:0 inet static
      address 10.20.8.231
      netmask 255.255.255.0
      gateway 10.20.8.1
      up /sbin/route add 1.2.3.4 gw 10.20.8.1
      down /sbin/route del 1.2.3.4 gw 10.20.8.1


      From the multiple examples I have found online this should add routes when eth0:0 comes up but for some reason I can't get it to work.



      When I try to bring up the interface with ifup eth0:0 I get:



      RTNETLINK answers: File exists
      Failed to bring up eth0:0.


      Then, ifconfig shows eth0:0 is up but route -n does not show the new route. In fact it shows the exact same routes I had before. Nothing changed.



      Kernel IP routing table
      Destination Gateway Genmask Flags Metric Ref Use Iface
      0.0.0.0 10.20.8.1 0.0.0.0 UG 0 0 0 eth0
      10.20.8.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0


      This config is to be used on remote systems that can only be accessed via SSH. The whole idea is to keep eth0 set to dhcp as a backup when the site's network is changed (happened twice already) rendering the static ip unaccessible. The problem with this is that SSH (used by built in processes) uses the default route via eth0 and that doesn't work as the firewall (not managed by us) has been set to allow ssh only for the static IP on eth0:0.



      Note: In the example above 1.2.3.4 represents our ssh server and I am trying to route traffic via eth0:0 for that single host but after testing I may want to set the default route to use eth0:0 instead, but I also tried that and it failed the same way. I was using this line:



      up route add -net 0.0.0.0 netmask 0.0.0.0 gw 10.20.8.1





      Thank you for your assistance.










      share|improve this question
















      Here is my interfaces file:



      auto lo
      iface lo inet loopback

      auto eth0
      iface eth0 inet dhcp

      auto eth0:0
      iface eth0:0 inet static
      address 10.20.8.231
      netmask 255.255.255.0
      gateway 10.20.8.1
      up /sbin/route add 1.2.3.4 gw 10.20.8.1
      down /sbin/route del 1.2.3.4 gw 10.20.8.1


      From the multiple examples I have found online this should add routes when eth0:0 comes up but for some reason I can't get it to work.



      When I try to bring up the interface with ifup eth0:0 I get:



      RTNETLINK answers: File exists
      Failed to bring up eth0:0.


      Then, ifconfig shows eth0:0 is up but route -n does not show the new route. In fact it shows the exact same routes I had before. Nothing changed.



      Kernel IP routing table
      Destination Gateway Genmask Flags Metric Ref Use Iface
      0.0.0.0 10.20.8.1 0.0.0.0 UG 0 0 0 eth0
      10.20.8.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0


      This config is to be used on remote systems that can only be accessed via SSH. The whole idea is to keep eth0 set to dhcp as a backup when the site's network is changed (happened twice already) rendering the static ip unaccessible. The problem with this is that SSH (used by built in processes) uses the default route via eth0 and that doesn't work as the firewall (not managed by us) has been set to allow ssh only for the static IP on eth0:0.



      Note: In the example above 1.2.3.4 represents our ssh server and I am trying to route traffic via eth0:0 for that single host but after testing I may want to set the default route to use eth0:0 instead, but I also tried that and it failed the same way. I was using this line:



      up route add -net 0.0.0.0 netmask 0.0.0.0 gw 10.20.8.1





      Thank you for your assistance.







      debian networking dhcp ifconfig dhclient






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited May 15 '17 at 20:03









      Rui F Ribeiro

      39.5k1479133




      39.5k1479133










      asked Dec 21 '15 at 15:58









      TCZ8TCZ8

      5343820




      5343820






















          2 Answers
          2






          active

          oldest

          votes


















          0














          I do not find particularly a good idea to place secondary IP addresses first.



          The problem is far greater than you using the default route of eth0, as it is the first interface, when routing to other networks, your source IP is the DHCP IP address de facto and not 10.20.8.231.



          As such I would recommend placing your static address in eth0 in lieu of eth0:0 with the following configuration:



          auto eth0
          iface eth0 inet static
          address 10.20.8.231
          netmask 255.255.255.0
          gateway 10.20.8.1

          auto eth0:0
          iface eth0:0 inet dhcp





          share|improve this answer


























          • I completely agree with you but and I have two issues with this.think I tried adding routes in eth0's stanza and it also failed to add the routes but I will have to restest, my memory is fuzzy (tried to many things)

            – TCZ8
            Dec 21 '15 at 21:11











          • But it doesn't really matter as the default route will then be set to the proper IP and I won't need the extra route.

            – TCZ8
            Dec 21 '15 at 21:19













          • The second issue is that I tried setting eth0:0 to dhcp but when I run ifconfig eth0:0 up I get the error SIOCSIFFLAGS: Cannot assign requested address and when I try ifup eth0:0 I get Bind socket to interface: No such device Failed to bring up eth0:0. googling pointed me to unresolved issues with dhclient and mac address handling issues when dealing with virtual adapters. So I am not sure what else I can do, although this solution would be ideal.

            – TCZ8
            Dec 21 '15 at 21:25













          • now I understand the routes. try ifdown eth0:0 and then ifup eth0:0 Even if it gives the error do a ifconfig -a and check wether it worked

            – Rui F Ribeiro
            Dec 21 '15 at 23:19





















          0














          It seems ifupdown does not play well with lower-level tools like iproute2 or net-tools. It is mentioned as warning in the official Debian documentation:




          Warning



          Do not use low level configuration tools such as ifconfig(8) and ip(8)
          commands to configure an interface in up state.




          You may try to manually flush and disable your network interface before using ifupdown to fix your issue:



           # ip addr flush dev [interface_name]
          # ip link set down dev [interface_name]
          # ifdown [interface_name]
          # ifup [interface_name]





          share|improve this answer

























            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',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            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%2f250737%2fwhy-are-routes-set-in-etc-network-interfaces-not-added-when-the-interface-comes%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            I do not find particularly a good idea to place secondary IP addresses first.



            The problem is far greater than you using the default route of eth0, as it is the first interface, when routing to other networks, your source IP is the DHCP IP address de facto and not 10.20.8.231.



            As such I would recommend placing your static address in eth0 in lieu of eth0:0 with the following configuration:



            auto eth0
            iface eth0 inet static
            address 10.20.8.231
            netmask 255.255.255.0
            gateway 10.20.8.1

            auto eth0:0
            iface eth0:0 inet dhcp





            share|improve this answer


























            • I completely agree with you but and I have two issues with this.think I tried adding routes in eth0's stanza and it also failed to add the routes but I will have to restest, my memory is fuzzy (tried to many things)

              – TCZ8
              Dec 21 '15 at 21:11











            • But it doesn't really matter as the default route will then be set to the proper IP and I won't need the extra route.

              – TCZ8
              Dec 21 '15 at 21:19













            • The second issue is that I tried setting eth0:0 to dhcp but when I run ifconfig eth0:0 up I get the error SIOCSIFFLAGS: Cannot assign requested address and when I try ifup eth0:0 I get Bind socket to interface: No such device Failed to bring up eth0:0. googling pointed me to unresolved issues with dhclient and mac address handling issues when dealing with virtual adapters. So I am not sure what else I can do, although this solution would be ideal.

              – TCZ8
              Dec 21 '15 at 21:25













            • now I understand the routes. try ifdown eth0:0 and then ifup eth0:0 Even if it gives the error do a ifconfig -a and check wether it worked

              – Rui F Ribeiro
              Dec 21 '15 at 23:19


















            0














            I do not find particularly a good idea to place secondary IP addresses first.



            The problem is far greater than you using the default route of eth0, as it is the first interface, when routing to other networks, your source IP is the DHCP IP address de facto and not 10.20.8.231.



            As such I would recommend placing your static address in eth0 in lieu of eth0:0 with the following configuration:



            auto eth0
            iface eth0 inet static
            address 10.20.8.231
            netmask 255.255.255.0
            gateway 10.20.8.1

            auto eth0:0
            iface eth0:0 inet dhcp





            share|improve this answer


























            • I completely agree with you but and I have two issues with this.think I tried adding routes in eth0's stanza and it also failed to add the routes but I will have to restest, my memory is fuzzy (tried to many things)

              – TCZ8
              Dec 21 '15 at 21:11











            • But it doesn't really matter as the default route will then be set to the proper IP and I won't need the extra route.

              – TCZ8
              Dec 21 '15 at 21:19













            • The second issue is that I tried setting eth0:0 to dhcp but when I run ifconfig eth0:0 up I get the error SIOCSIFFLAGS: Cannot assign requested address and when I try ifup eth0:0 I get Bind socket to interface: No such device Failed to bring up eth0:0. googling pointed me to unresolved issues with dhclient and mac address handling issues when dealing with virtual adapters. So I am not sure what else I can do, although this solution would be ideal.

              – TCZ8
              Dec 21 '15 at 21:25













            • now I understand the routes. try ifdown eth0:0 and then ifup eth0:0 Even if it gives the error do a ifconfig -a and check wether it worked

              – Rui F Ribeiro
              Dec 21 '15 at 23:19
















            0












            0








            0







            I do not find particularly a good idea to place secondary IP addresses first.



            The problem is far greater than you using the default route of eth0, as it is the first interface, when routing to other networks, your source IP is the DHCP IP address de facto and not 10.20.8.231.



            As such I would recommend placing your static address in eth0 in lieu of eth0:0 with the following configuration:



            auto eth0
            iface eth0 inet static
            address 10.20.8.231
            netmask 255.255.255.0
            gateway 10.20.8.1

            auto eth0:0
            iface eth0:0 inet dhcp





            share|improve this answer















            I do not find particularly a good idea to place secondary IP addresses first.



            The problem is far greater than you using the default route of eth0, as it is the first interface, when routing to other networks, your source IP is the DHCP IP address de facto and not 10.20.8.231.



            As such I would recommend placing your static address in eth0 in lieu of eth0:0 with the following configuration:



            auto eth0
            iface eth0 inet static
            address 10.20.8.231
            netmask 255.255.255.0
            gateway 10.20.8.1

            auto eth0:0
            iface eth0:0 inet dhcp






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Dec 21 '15 at 23:11

























            answered Dec 21 '15 at 16:24









            Rui F RibeiroRui F Ribeiro

            39.5k1479133




            39.5k1479133













            • I completely agree with you but and I have two issues with this.think I tried adding routes in eth0's stanza and it also failed to add the routes but I will have to restest, my memory is fuzzy (tried to many things)

              – TCZ8
              Dec 21 '15 at 21:11











            • But it doesn't really matter as the default route will then be set to the proper IP and I won't need the extra route.

              – TCZ8
              Dec 21 '15 at 21:19













            • The second issue is that I tried setting eth0:0 to dhcp but when I run ifconfig eth0:0 up I get the error SIOCSIFFLAGS: Cannot assign requested address and when I try ifup eth0:0 I get Bind socket to interface: No such device Failed to bring up eth0:0. googling pointed me to unresolved issues with dhclient and mac address handling issues when dealing with virtual adapters. So I am not sure what else I can do, although this solution would be ideal.

              – TCZ8
              Dec 21 '15 at 21:25













            • now I understand the routes. try ifdown eth0:0 and then ifup eth0:0 Even if it gives the error do a ifconfig -a and check wether it worked

              – Rui F Ribeiro
              Dec 21 '15 at 23:19





















            • I completely agree with you but and I have two issues with this.think I tried adding routes in eth0's stanza and it also failed to add the routes but I will have to restest, my memory is fuzzy (tried to many things)

              – TCZ8
              Dec 21 '15 at 21:11











            • But it doesn't really matter as the default route will then be set to the proper IP and I won't need the extra route.

              – TCZ8
              Dec 21 '15 at 21:19













            • The second issue is that I tried setting eth0:0 to dhcp but when I run ifconfig eth0:0 up I get the error SIOCSIFFLAGS: Cannot assign requested address and when I try ifup eth0:0 I get Bind socket to interface: No such device Failed to bring up eth0:0. googling pointed me to unresolved issues with dhclient and mac address handling issues when dealing with virtual adapters. So I am not sure what else I can do, although this solution would be ideal.

              – TCZ8
              Dec 21 '15 at 21:25













            • now I understand the routes. try ifdown eth0:0 and then ifup eth0:0 Even if it gives the error do a ifconfig -a and check wether it worked

              – Rui F Ribeiro
              Dec 21 '15 at 23:19



















            I completely agree with you but and I have two issues with this.think I tried adding routes in eth0's stanza and it also failed to add the routes but I will have to restest, my memory is fuzzy (tried to many things)

            – TCZ8
            Dec 21 '15 at 21:11





            I completely agree with you but and I have two issues with this.think I tried adding routes in eth0's stanza and it also failed to add the routes but I will have to restest, my memory is fuzzy (tried to many things)

            – TCZ8
            Dec 21 '15 at 21:11













            But it doesn't really matter as the default route will then be set to the proper IP and I won't need the extra route.

            – TCZ8
            Dec 21 '15 at 21:19







            But it doesn't really matter as the default route will then be set to the proper IP and I won't need the extra route.

            – TCZ8
            Dec 21 '15 at 21:19















            The second issue is that I tried setting eth0:0 to dhcp but when I run ifconfig eth0:0 up I get the error SIOCSIFFLAGS: Cannot assign requested address and when I try ifup eth0:0 I get Bind socket to interface: No such device Failed to bring up eth0:0. googling pointed me to unresolved issues with dhclient and mac address handling issues when dealing with virtual adapters. So I am not sure what else I can do, although this solution would be ideal.

            – TCZ8
            Dec 21 '15 at 21:25







            The second issue is that I tried setting eth0:0 to dhcp but when I run ifconfig eth0:0 up I get the error SIOCSIFFLAGS: Cannot assign requested address and when I try ifup eth0:0 I get Bind socket to interface: No such device Failed to bring up eth0:0. googling pointed me to unresolved issues with dhclient and mac address handling issues when dealing with virtual adapters. So I am not sure what else I can do, although this solution would be ideal.

            – TCZ8
            Dec 21 '15 at 21:25















            now I understand the routes. try ifdown eth0:0 and then ifup eth0:0 Even if it gives the error do a ifconfig -a and check wether it worked

            – Rui F Ribeiro
            Dec 21 '15 at 23:19







            now I understand the routes. try ifdown eth0:0 and then ifup eth0:0 Even if it gives the error do a ifconfig -a and check wether it worked

            – Rui F Ribeiro
            Dec 21 '15 at 23:19















            0














            It seems ifupdown does not play well with lower-level tools like iproute2 or net-tools. It is mentioned as warning in the official Debian documentation:




            Warning



            Do not use low level configuration tools such as ifconfig(8) and ip(8)
            commands to configure an interface in up state.




            You may try to manually flush and disable your network interface before using ifupdown to fix your issue:



             # ip addr flush dev [interface_name]
            # ip link set down dev [interface_name]
            # ifdown [interface_name]
            # ifup [interface_name]





            share|improve this answer






























              0














              It seems ifupdown does not play well with lower-level tools like iproute2 or net-tools. It is mentioned as warning in the official Debian documentation:




              Warning



              Do not use low level configuration tools such as ifconfig(8) and ip(8)
              commands to configure an interface in up state.




              You may try to manually flush and disable your network interface before using ifupdown to fix your issue:



               # ip addr flush dev [interface_name]
              # ip link set down dev [interface_name]
              # ifdown [interface_name]
              # ifup [interface_name]





              share|improve this answer




























                0












                0








                0







                It seems ifupdown does not play well with lower-level tools like iproute2 or net-tools. It is mentioned as warning in the official Debian documentation:




                Warning



                Do not use low level configuration tools such as ifconfig(8) and ip(8)
                commands to configure an interface in up state.




                You may try to manually flush and disable your network interface before using ifupdown to fix your issue:



                 # ip addr flush dev [interface_name]
                # ip link set down dev [interface_name]
                # ifdown [interface_name]
                # ifup [interface_name]





                share|improve this answer















                It seems ifupdown does not play well with lower-level tools like iproute2 or net-tools. It is mentioned as warning in the official Debian documentation:




                Warning



                Do not use low level configuration tools such as ifconfig(8) and ip(8)
                commands to configure an interface in up state.




                You may try to manually flush and disable your network interface before using ifupdown to fix your issue:



                 # ip addr flush dev [interface_name]
                # ip link set down dev [interface_name]
                # ifdown [interface_name]
                # ifup [interface_name]






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Oct 14 '16 at 8:53

























                answered Oct 14 '16 at 8:20









                pedroaperopedroapero

                376212




                376212






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid



                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.


                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f250737%2fwhy-are-routes-set-in-etc-network-interfaces-not-added-when-the-interface-comes%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown







                    Popular posts from this blog

                    Morgemoulin

                    Scott Moir

                    Souastre