In Linux, what metric has a route with no metric?











up vote
4
down vote

favorite
1












If you have (in Linux) these two routes:



default via 192.168.1.1 dev enp58s0f1
default via 192.168.16.1 dev wlp59s0 proto static metric 600


I would expect that the first one is used, but that's not the case: the second one is used instead.



If I change that to this:



default via 192.168.1.1 dev enp58s0f1  proto static  metric 100 
default via 192.168.16.1 dev wlp59s0 proto static metric 600


Then it works as expected. It seems that "no metric" is a worse (higher) metric than any number, instead of metric 0.



What is this happening? Is it specific to Linux, or a networking standard?



Thanks in advance.










share|improve this question


























    up vote
    4
    down vote

    favorite
    1












    If you have (in Linux) these two routes:



    default via 192.168.1.1 dev enp58s0f1
    default via 192.168.16.1 dev wlp59s0 proto static metric 600


    I would expect that the first one is used, but that's not the case: the second one is used instead.



    If I change that to this:



    default via 192.168.1.1 dev enp58s0f1  proto static  metric 100 
    default via 192.168.16.1 dev wlp59s0 proto static metric 600


    Then it works as expected. It seems that "no metric" is a worse (higher) metric than any number, instead of metric 0.



    What is this happening? Is it specific to Linux, or a networking standard?



    Thanks in advance.










    share|improve this question
























      up vote
      4
      down vote

      favorite
      1









      up vote
      4
      down vote

      favorite
      1






      1





      If you have (in Linux) these two routes:



      default via 192.168.1.1 dev enp58s0f1
      default via 192.168.16.1 dev wlp59s0 proto static metric 600


      I would expect that the first one is used, but that's not the case: the second one is used instead.



      If I change that to this:



      default via 192.168.1.1 dev enp58s0f1  proto static  metric 100 
      default via 192.168.16.1 dev wlp59s0 proto static metric 600


      Then it works as expected. It seems that "no metric" is a worse (higher) metric than any number, instead of metric 0.



      What is this happening? Is it specific to Linux, or a networking standard?



      Thanks in advance.










      share|improve this question













      If you have (in Linux) these two routes:



      default via 192.168.1.1 dev enp58s0f1
      default via 192.168.16.1 dev wlp59s0 proto static metric 600


      I would expect that the first one is used, but that's not the case: the second one is used instead.



      If I change that to this:



      default via 192.168.1.1 dev enp58s0f1  proto static  metric 100 
      default via 192.168.16.1 dev wlp59s0 proto static metric 600


      Then it works as expected. It seems that "no metric" is a worse (higher) metric than any number, instead of metric 0.



      What is this happening? Is it specific to Linux, or a networking standard?



      Thanks in advance.







      linux networking routing






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 22 at 15:29









      rsuarez

      459418




      459418






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          2
          down vote













          Are you sure about your first observation? What does ip route show or route -n show then? Does the result change if you add proto static in first case?



          I have found at least two resources that explicitely says that 0 is the default value in Linux:





          • http://0pointer.de/lennart/projects/ifmetric/ : The default metric for a route in the Linux kernel is 0, meaning the highest priority.


          • http://www.man7.org/linux/man-pages/man8/route.8.html : If this option is not specified the metric for inet6 (IPv6) address family defaults to '1', for inet (IPv4) it defaults to '0'. (it then hints that the default may be different when using iproute2 but analysis of these sources do not show what it is)


          A Linux kernel hacker would surely be needed to sort that out.



          Also whatever default is chosen is clearly OS specific.
          This article (https://support.microsoft.com/en-us/help/299540/an-explanation-of-the-automatic-metric-feature-for-ipv4-routes) for example shows that Windows choose the default metric based on the bandwidth of the link.






          share|improve this answer




























            up vote
            1
            down vote













            Since these routes are on different subnets, there's more involved here than just the metric. If originating traffic is on the 192.168.1.1 subnet, for instance, and there is a matching non-default route in your routing table, then that route will match via longest prefix match before the metric is ever considered.



            Assuming a non-default route is not matching, then having no metric should be interpreted by the kernel as having a metric of 0, and therefore the highest priority route. Although that's a simplistic view because some routing daemons will later translate that default metric into another value like 1024. I expect this is what is happening to you and your unnamed distro.



            If ip route shows no metric at all, you can confirm that it is indeed 0 by using the older route -n command from the net-tools package or cat /proc/net/route. However, this output doesn't necessarily match what the routing daemon will use internally when it encounters a 0 metric value.



            Furthermore how you create the route matters too. ip route uses the netlink API, while route uses ioctl. The code for how default metrics are created between the two approaches result in different metric values. For instance: creating an IPv6 default route via ip route will result in a metric value of 1024 on RHEL 7, while creating the same route via route will result in a metric of 1.



            From RedHat:





            • if nothing is passed to the route command as route metric the value of 1 is used by the command itself.

            • If nothing is passed to the ip command as route metric the attribute is not created at all and kernel understands to it as 0, which is later translated 1024 as default.







            share|improve this answer










            New contributor




            noobish is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
            Check out our Code of Conduct.


















              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: 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%2f425924%2fin-linux-what-metric-has-a-route-with-no-metric%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








              up vote
              2
              down vote













              Are you sure about your first observation? What does ip route show or route -n show then? Does the result change if you add proto static in first case?



              I have found at least two resources that explicitely says that 0 is the default value in Linux:





              • http://0pointer.de/lennart/projects/ifmetric/ : The default metric for a route in the Linux kernel is 0, meaning the highest priority.


              • http://www.man7.org/linux/man-pages/man8/route.8.html : If this option is not specified the metric for inet6 (IPv6) address family defaults to '1', for inet (IPv4) it defaults to '0'. (it then hints that the default may be different when using iproute2 but analysis of these sources do not show what it is)


              A Linux kernel hacker would surely be needed to sort that out.



              Also whatever default is chosen is clearly OS specific.
              This article (https://support.microsoft.com/en-us/help/299540/an-explanation-of-the-automatic-metric-feature-for-ipv4-routes) for example shows that Windows choose the default metric based on the bandwidth of the link.






              share|improve this answer

























                up vote
                2
                down vote













                Are you sure about your first observation? What does ip route show or route -n show then? Does the result change if you add proto static in first case?



                I have found at least two resources that explicitely says that 0 is the default value in Linux:





                • http://0pointer.de/lennart/projects/ifmetric/ : The default metric for a route in the Linux kernel is 0, meaning the highest priority.


                • http://www.man7.org/linux/man-pages/man8/route.8.html : If this option is not specified the metric for inet6 (IPv6) address family defaults to '1', for inet (IPv4) it defaults to '0'. (it then hints that the default may be different when using iproute2 but analysis of these sources do not show what it is)


                A Linux kernel hacker would surely be needed to sort that out.



                Also whatever default is chosen is clearly OS specific.
                This article (https://support.microsoft.com/en-us/help/299540/an-explanation-of-the-automatic-metric-feature-for-ipv4-routes) for example shows that Windows choose the default metric based on the bandwidth of the link.






                share|improve this answer























                  up vote
                  2
                  down vote










                  up vote
                  2
                  down vote









                  Are you sure about your first observation? What does ip route show or route -n show then? Does the result change if you add proto static in first case?



                  I have found at least two resources that explicitely says that 0 is the default value in Linux:





                  • http://0pointer.de/lennart/projects/ifmetric/ : The default metric for a route in the Linux kernel is 0, meaning the highest priority.


                  • http://www.man7.org/linux/man-pages/man8/route.8.html : If this option is not specified the metric for inet6 (IPv6) address family defaults to '1', for inet (IPv4) it defaults to '0'. (it then hints that the default may be different when using iproute2 but analysis of these sources do not show what it is)


                  A Linux kernel hacker would surely be needed to sort that out.



                  Also whatever default is chosen is clearly OS specific.
                  This article (https://support.microsoft.com/en-us/help/299540/an-explanation-of-the-automatic-metric-feature-for-ipv4-routes) for example shows that Windows choose the default metric based on the bandwidth of the link.






                  share|improve this answer












                  Are you sure about your first observation? What does ip route show or route -n show then? Does the result change if you add proto static in first case?



                  I have found at least two resources that explicitely says that 0 is the default value in Linux:





                  • http://0pointer.de/lennart/projects/ifmetric/ : The default metric for a route in the Linux kernel is 0, meaning the highest priority.


                  • http://www.man7.org/linux/man-pages/man8/route.8.html : If this option is not specified the metric for inet6 (IPv6) address family defaults to '1', for inet (IPv4) it defaults to '0'. (it then hints that the default may be different when using iproute2 but analysis of these sources do not show what it is)


                  A Linux kernel hacker would surely be needed to sort that out.



                  Also whatever default is chosen is clearly OS specific.
                  This article (https://support.microsoft.com/en-us/help/299540/an-explanation-of-the-automatic-metric-feature-for-ipv4-routes) for example shows that Windows choose the default metric based on the bandwidth of the link.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Mar 17 at 21:54









                  Patrick Mevzek

                  2,1041821




                  2,1041821
























                      up vote
                      1
                      down vote













                      Since these routes are on different subnets, there's more involved here than just the metric. If originating traffic is on the 192.168.1.1 subnet, for instance, and there is a matching non-default route in your routing table, then that route will match via longest prefix match before the metric is ever considered.



                      Assuming a non-default route is not matching, then having no metric should be interpreted by the kernel as having a metric of 0, and therefore the highest priority route. Although that's a simplistic view because some routing daemons will later translate that default metric into another value like 1024. I expect this is what is happening to you and your unnamed distro.



                      If ip route shows no metric at all, you can confirm that it is indeed 0 by using the older route -n command from the net-tools package or cat /proc/net/route. However, this output doesn't necessarily match what the routing daemon will use internally when it encounters a 0 metric value.



                      Furthermore how you create the route matters too. ip route uses the netlink API, while route uses ioctl. The code for how default metrics are created between the two approaches result in different metric values. For instance: creating an IPv6 default route via ip route will result in a metric value of 1024 on RHEL 7, while creating the same route via route will result in a metric of 1.



                      From RedHat:





                      • if nothing is passed to the route command as route metric the value of 1 is used by the command itself.

                      • If nothing is passed to the ip command as route metric the attribute is not created at all and kernel understands to it as 0, which is later translated 1024 as default.







                      share|improve this answer










                      New contributor




                      noobish is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                      Check out our Code of Conduct.






















                        up vote
                        1
                        down vote













                        Since these routes are on different subnets, there's more involved here than just the metric. If originating traffic is on the 192.168.1.1 subnet, for instance, and there is a matching non-default route in your routing table, then that route will match via longest prefix match before the metric is ever considered.



                        Assuming a non-default route is not matching, then having no metric should be interpreted by the kernel as having a metric of 0, and therefore the highest priority route. Although that's a simplistic view because some routing daemons will later translate that default metric into another value like 1024. I expect this is what is happening to you and your unnamed distro.



                        If ip route shows no metric at all, you can confirm that it is indeed 0 by using the older route -n command from the net-tools package or cat /proc/net/route. However, this output doesn't necessarily match what the routing daemon will use internally when it encounters a 0 metric value.



                        Furthermore how you create the route matters too. ip route uses the netlink API, while route uses ioctl. The code for how default metrics are created between the two approaches result in different metric values. For instance: creating an IPv6 default route via ip route will result in a metric value of 1024 on RHEL 7, while creating the same route via route will result in a metric of 1.



                        From RedHat:





                        • if nothing is passed to the route command as route metric the value of 1 is used by the command itself.

                        • If nothing is passed to the ip command as route metric the attribute is not created at all and kernel understands to it as 0, which is later translated 1024 as default.







                        share|improve this answer










                        New contributor




                        noobish is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                        Check out our Code of Conduct.




















                          up vote
                          1
                          down vote










                          up vote
                          1
                          down vote









                          Since these routes are on different subnets, there's more involved here than just the metric. If originating traffic is on the 192.168.1.1 subnet, for instance, and there is a matching non-default route in your routing table, then that route will match via longest prefix match before the metric is ever considered.



                          Assuming a non-default route is not matching, then having no metric should be interpreted by the kernel as having a metric of 0, and therefore the highest priority route. Although that's a simplistic view because some routing daemons will later translate that default metric into another value like 1024. I expect this is what is happening to you and your unnamed distro.



                          If ip route shows no metric at all, you can confirm that it is indeed 0 by using the older route -n command from the net-tools package or cat /proc/net/route. However, this output doesn't necessarily match what the routing daemon will use internally when it encounters a 0 metric value.



                          Furthermore how you create the route matters too. ip route uses the netlink API, while route uses ioctl. The code for how default metrics are created between the two approaches result in different metric values. For instance: creating an IPv6 default route via ip route will result in a metric value of 1024 on RHEL 7, while creating the same route via route will result in a metric of 1.



                          From RedHat:





                          • if nothing is passed to the route command as route metric the value of 1 is used by the command itself.

                          • If nothing is passed to the ip command as route metric the attribute is not created at all and kernel understands to it as 0, which is later translated 1024 as default.







                          share|improve this answer










                          New contributor




                          noobish is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          Since these routes are on different subnets, there's more involved here than just the metric. If originating traffic is on the 192.168.1.1 subnet, for instance, and there is a matching non-default route in your routing table, then that route will match via longest prefix match before the metric is ever considered.



                          Assuming a non-default route is not matching, then having no metric should be interpreted by the kernel as having a metric of 0, and therefore the highest priority route. Although that's a simplistic view because some routing daemons will later translate that default metric into another value like 1024. I expect this is what is happening to you and your unnamed distro.



                          If ip route shows no metric at all, you can confirm that it is indeed 0 by using the older route -n command from the net-tools package or cat /proc/net/route. However, this output doesn't necessarily match what the routing daemon will use internally when it encounters a 0 metric value.



                          Furthermore how you create the route matters too. ip route uses the netlink API, while route uses ioctl. The code for how default metrics are created between the two approaches result in different metric values. For instance: creating an IPv6 default route via ip route will result in a metric value of 1024 on RHEL 7, while creating the same route via route will result in a metric of 1.



                          From RedHat:





                          • if nothing is passed to the route command as route metric the value of 1 is used by the command itself.

                          • If nothing is passed to the ip command as route metric the attribute is not created at all and kernel understands to it as 0, which is later translated 1024 as default.








                          share|improve this answer










                          New contributor




                          noobish is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          share|improve this answer



                          share|improve this answer








                          edited Nov 28 at 1:58





















                          New contributor




                          noobish is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.









                          answered Nov 27 at 23:47









                          noobish

                          1112




                          1112




                          New contributor




                          noobish is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.





                          New contributor





                          noobish is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






                          noobish is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
                          Check out our Code of Conduct.






























                              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.





                              Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                              Please pay close attention to the following guidance:


                              • 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%2f425924%2fin-linux-what-metric-has-a-route-with-no-metric%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

                              Entries order in /etc/network/interfaces

                              新発田市

                              Grub takes very long (several minutes) to open Menu (in Multi-Boot-System)