How can I make changes to the network routing metric permanently

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












7















I'm able change my network routing metrics with ifmetric, for example ifmetric enp0s3 1.



Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 1 0 0 enp0s3
0.0.0.0 192.168.237.1 0.0.0.0 UG 100 0 0 enp0s8


When I reboot though, the metric for enp0s3 reverts to 101. How can I make this change permanent or have it set automatically at boot time?










share|improve this question
























  • See unix.stackexchange.com/a/498676/173437

    – Jithin Pavithran
    Feb 4 at 22:04















7















I'm able change my network routing metrics with ifmetric, for example ifmetric enp0s3 1.



Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 1 0 0 enp0s3
0.0.0.0 192.168.237.1 0.0.0.0 UG 100 0 0 enp0s8


When I reboot though, the metric for enp0s3 reverts to 101. How can I make this change permanent or have it set automatically at boot time?










share|improve this question
























  • See unix.stackexchange.com/a/498676/173437

    – Jithin Pavithran
    Feb 4 at 22:04













7












7








7








I'm able change my network routing metrics with ifmetric, for example ifmetric enp0s3 1.



Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 1 0 0 enp0s3
0.0.0.0 192.168.237.1 0.0.0.0 UG 100 0 0 enp0s8


When I reboot though, the metric for enp0s3 reverts to 101. How can I make this change permanent or have it set automatically at boot time?










share|improve this question
















I'm able change my network routing metrics with ifmetric, for example ifmetric enp0s3 1.



Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 192.168.1.1 0.0.0.0 UG 1 0 0 enp0s3
0.0.0.0 192.168.237.1 0.0.0.0 UG 100 0 0 enp0s8


When I reboot though, the metric for enp0s3 reverts to 101. How can I make this change permanent or have it set automatically at boot time?







ubuntu networking routing network-interface






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 14 '17 at 17:32









Rui F Ribeiro

40.5k1479137




40.5k1479137










asked Feb 14 '17 at 17:19









marathonmarathon

296415




296415












  • See unix.stackexchange.com/a/498676/173437

    – Jithin Pavithran
    Feb 4 at 22:04

















  • See unix.stackexchange.com/a/498676/173437

    – Jithin Pavithran
    Feb 4 at 22:04
















See unix.stackexchange.com/a/498676/173437

– Jithin Pavithran
Feb 4 at 22:04





See unix.stackexchange.com/a/498676/173437

– Jithin Pavithran
Feb 4 at 22:04










4 Answers
4






active

oldest

votes


















5














The correct way to do this, in Debian and derivatives, is to write a file in /etc/NetworkManager/dispatcher.d (call it whatever you like), with the following content:



#!/bin/sh

# Change the metric of the default route only on interface enp0s3

IF=$1
STATUS=$2
MY_METRIC=1

if [ "$IF" = "enp0s3" ]
then
case "$STATUS" in
up)
ip route del default dev $IF
ip route add default via $DHCP4_ROUTERS dev $IF metric $MY_METRIC
;;
*)
;;
esac
fi


This way, your customization will not be overwritten upon each update.
In order to check this, stop the Network Manager, kill the dhclient and flush the IP address of the interface, then restart network manager.



You can find documentation here.






share|improve this answer
































    5














    If you are using NetworkManager, the proper way to change the metric for the default route is to modify the connection associated with interface enp0s3 in this way:



    nmcli connection modify <connection-name> ipv4.route-metric 1


    and then re-activate the connection:



    nmcli connection up <connection-name>


    You can find the value for <connection-name> in the output of nmcli connection.






    share|improve this answer






























      1














      You should be able to make it permanent in /etc/dhcpd.conf where you can set an interface metric like this.



      interface enp0s3;
      metric 1;





      share|improve this answer























      • Um, I don't think so. What is the os? Also try and see if this exists /etc/conf.d/dhcpcd

        – Pythonic
        Feb 14 '17 at 17:58











      • tried creating this file with your settings - it did not work. Ubuntu 16.10. Thanks though.

        – marathon
        Feb 15 '17 at 4:24











      • didn't work with me either

        – Guerlando OCs
        Jul 4 '18 at 17:52


















      1














      The easiest and right way to do this is by editing /etc/network/interfaces.



      Here is a simple example of /etc/network/interfaces:



      auto lo eth0
      iface lo inet loopback

      allow-hotplug eth0
      iface eth0 inet dhcp
      metric 700


      Restart networking using service networking restart for the changes to take place.



      Ref: Section 5.7.2. The ifmetric package of Debian Manual




      The following sets the eth0 interface to be preferred over the wlan0
      interface.



      Install the ifmetric package.



      Add an option line with "metric 0" just below the "iface eth0 inet
      dhcp" line in "/etc/network/interfaces".



      Add an option line with "metric 1" just below the "iface wlan0 inet
      dhcp" line in "/etc/network/interfaces".




      Extra Note:




      • auto <interface1> <interface2> starts interfaces on start of the system.


      • allow-hotplug <interface> starts the interface on hotplug event.





      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%2f344974%2fhow-can-i-make-changes-to-the-network-routing-metric-permanently%23new-answer', 'question_page');

        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        5














        The correct way to do this, in Debian and derivatives, is to write a file in /etc/NetworkManager/dispatcher.d (call it whatever you like), with the following content:



        #!/bin/sh

        # Change the metric of the default route only on interface enp0s3

        IF=$1
        STATUS=$2
        MY_METRIC=1

        if [ "$IF" = "enp0s3" ]
        then
        case "$STATUS" in
        up)
        ip route del default dev $IF
        ip route add default via $DHCP4_ROUTERS dev $IF metric $MY_METRIC
        ;;
        *)
        ;;
        esac
        fi


        This way, your customization will not be overwritten upon each update.
        In order to check this, stop the Network Manager, kill the dhclient and flush the IP address of the interface, then restart network manager.



        You can find documentation here.






        share|improve this answer





























          5














          The correct way to do this, in Debian and derivatives, is to write a file in /etc/NetworkManager/dispatcher.d (call it whatever you like), with the following content:



          #!/bin/sh

          # Change the metric of the default route only on interface enp0s3

          IF=$1
          STATUS=$2
          MY_METRIC=1

          if [ "$IF" = "enp0s3" ]
          then
          case "$STATUS" in
          up)
          ip route del default dev $IF
          ip route add default via $DHCP4_ROUTERS dev $IF metric $MY_METRIC
          ;;
          *)
          ;;
          esac
          fi


          This way, your customization will not be overwritten upon each update.
          In order to check this, stop the Network Manager, kill the dhclient and flush the IP address of the interface, then restart network manager.



          You can find documentation here.






          share|improve this answer



























            5












            5








            5







            The correct way to do this, in Debian and derivatives, is to write a file in /etc/NetworkManager/dispatcher.d (call it whatever you like), with the following content:



            #!/bin/sh

            # Change the metric of the default route only on interface enp0s3

            IF=$1
            STATUS=$2
            MY_METRIC=1

            if [ "$IF" = "enp0s3" ]
            then
            case "$STATUS" in
            up)
            ip route del default dev $IF
            ip route add default via $DHCP4_ROUTERS dev $IF metric $MY_METRIC
            ;;
            *)
            ;;
            esac
            fi


            This way, your customization will not be overwritten upon each update.
            In order to check this, stop the Network Manager, kill the dhclient and flush the IP address of the interface, then restart network manager.



            You can find documentation here.






            share|improve this answer















            The correct way to do this, in Debian and derivatives, is to write a file in /etc/NetworkManager/dispatcher.d (call it whatever you like), with the following content:



            #!/bin/sh

            # Change the metric of the default route only on interface enp0s3

            IF=$1
            STATUS=$2
            MY_METRIC=1

            if [ "$IF" = "enp0s3" ]
            then
            case "$STATUS" in
            up)
            ip route del default dev $IF
            ip route add default via $DHCP4_ROUTERS dev $IF metric $MY_METRIC
            ;;
            *)
            ;;
            esac
            fi


            This way, your customization will not be overwritten upon each update.
            In order to check this, stop the Network Manager, kill the dhclient and flush the IP address of the interface, then restart network manager.



            You can find documentation here.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Feb 15 '17 at 5:37

























            answered Feb 14 '17 at 23:12









            MariusMatutiaeMariusMatutiae

            3,43011325




            3,43011325























                5














                If you are using NetworkManager, the proper way to change the metric for the default route is to modify the connection associated with interface enp0s3 in this way:



                nmcli connection modify <connection-name> ipv4.route-metric 1


                and then re-activate the connection:



                nmcli connection up <connection-name>


                You can find the value for <connection-name> in the output of nmcli connection.






                share|improve this answer



























                  5














                  If you are using NetworkManager, the proper way to change the metric for the default route is to modify the connection associated with interface enp0s3 in this way:



                  nmcli connection modify <connection-name> ipv4.route-metric 1


                  and then re-activate the connection:



                  nmcli connection up <connection-name>


                  You can find the value for <connection-name> in the output of nmcli connection.






                  share|improve this answer

























                    5












                    5








                    5







                    If you are using NetworkManager, the proper way to change the metric for the default route is to modify the connection associated with interface enp0s3 in this way:



                    nmcli connection modify <connection-name> ipv4.route-metric 1


                    and then re-activate the connection:



                    nmcli connection up <connection-name>


                    You can find the value for <connection-name> in the output of nmcli connection.






                    share|improve this answer













                    If you are using NetworkManager, the proper way to change the metric for the default route is to modify the connection associated with interface enp0s3 in this way:



                    nmcli connection modify <connection-name> ipv4.route-metric 1


                    and then re-activate the connection:



                    nmcli connection up <connection-name>


                    You can find the value for <connection-name> in the output of nmcli connection.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Mar 5 '17 at 22:17









                    bengalbengal

                    892




                    892





















                        1














                        You should be able to make it permanent in /etc/dhcpd.conf where you can set an interface metric like this.



                        interface enp0s3;
                        metric 1;





                        share|improve this answer























                        • Um, I don't think so. What is the os? Also try and see if this exists /etc/conf.d/dhcpcd

                          – Pythonic
                          Feb 14 '17 at 17:58











                        • tried creating this file with your settings - it did not work. Ubuntu 16.10. Thanks though.

                          – marathon
                          Feb 15 '17 at 4:24











                        • didn't work with me either

                          – Guerlando OCs
                          Jul 4 '18 at 17:52















                        1














                        You should be able to make it permanent in /etc/dhcpd.conf where you can set an interface metric like this.



                        interface enp0s3;
                        metric 1;





                        share|improve this answer























                        • Um, I don't think so. What is the os? Also try and see if this exists /etc/conf.d/dhcpcd

                          – Pythonic
                          Feb 14 '17 at 17:58











                        • tried creating this file with your settings - it did not work. Ubuntu 16.10. Thanks though.

                          – marathon
                          Feb 15 '17 at 4:24











                        • didn't work with me either

                          – Guerlando OCs
                          Jul 4 '18 at 17:52













                        1












                        1








                        1







                        You should be able to make it permanent in /etc/dhcpd.conf where you can set an interface metric like this.



                        interface enp0s3;
                        metric 1;





                        share|improve this answer













                        You should be able to make it permanent in /etc/dhcpd.conf where you can set an interface metric like this.



                        interface enp0s3;
                        metric 1;






                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Feb 14 '17 at 17:39









                        PythonicPythonic

                        419413




                        419413












                        • Um, I don't think so. What is the os? Also try and see if this exists /etc/conf.d/dhcpcd

                          – Pythonic
                          Feb 14 '17 at 17:58











                        • tried creating this file with your settings - it did not work. Ubuntu 16.10. Thanks though.

                          – marathon
                          Feb 15 '17 at 4:24











                        • didn't work with me either

                          – Guerlando OCs
                          Jul 4 '18 at 17:52

















                        • Um, I don't think so. What is the os? Also try and see if this exists /etc/conf.d/dhcpcd

                          – Pythonic
                          Feb 14 '17 at 17:58











                        • tried creating this file with your settings - it did not work. Ubuntu 16.10. Thanks though.

                          – marathon
                          Feb 15 '17 at 4:24











                        • didn't work with me either

                          – Guerlando OCs
                          Jul 4 '18 at 17:52
















                        Um, I don't think so. What is the os? Also try and see if this exists /etc/conf.d/dhcpcd

                        – Pythonic
                        Feb 14 '17 at 17:58





                        Um, I don't think so. What is the os? Also try and see if this exists /etc/conf.d/dhcpcd

                        – Pythonic
                        Feb 14 '17 at 17:58













                        tried creating this file with your settings - it did not work. Ubuntu 16.10. Thanks though.

                        – marathon
                        Feb 15 '17 at 4:24





                        tried creating this file with your settings - it did not work. Ubuntu 16.10. Thanks though.

                        – marathon
                        Feb 15 '17 at 4:24













                        didn't work with me either

                        – Guerlando OCs
                        Jul 4 '18 at 17:52





                        didn't work with me either

                        – Guerlando OCs
                        Jul 4 '18 at 17:52











                        1














                        The easiest and right way to do this is by editing /etc/network/interfaces.



                        Here is a simple example of /etc/network/interfaces:



                        auto lo eth0
                        iface lo inet loopback

                        allow-hotplug eth0
                        iface eth0 inet dhcp
                        metric 700


                        Restart networking using service networking restart for the changes to take place.



                        Ref: Section 5.7.2. The ifmetric package of Debian Manual




                        The following sets the eth0 interface to be preferred over the wlan0
                        interface.



                        Install the ifmetric package.



                        Add an option line with "metric 0" just below the "iface eth0 inet
                        dhcp" line in "/etc/network/interfaces".



                        Add an option line with "metric 1" just below the "iface wlan0 inet
                        dhcp" line in "/etc/network/interfaces".




                        Extra Note:




                        • auto <interface1> <interface2> starts interfaces on start of the system.


                        • allow-hotplug <interface> starts the interface on hotplug event.





                        share|improve this answer





























                          1














                          The easiest and right way to do this is by editing /etc/network/interfaces.



                          Here is a simple example of /etc/network/interfaces:



                          auto lo eth0
                          iface lo inet loopback

                          allow-hotplug eth0
                          iface eth0 inet dhcp
                          metric 700


                          Restart networking using service networking restart for the changes to take place.



                          Ref: Section 5.7.2. The ifmetric package of Debian Manual




                          The following sets the eth0 interface to be preferred over the wlan0
                          interface.



                          Install the ifmetric package.



                          Add an option line with "metric 0" just below the "iface eth0 inet
                          dhcp" line in "/etc/network/interfaces".



                          Add an option line with "metric 1" just below the "iface wlan0 inet
                          dhcp" line in "/etc/network/interfaces".




                          Extra Note:




                          • auto <interface1> <interface2> starts interfaces on start of the system.


                          • allow-hotplug <interface> starts the interface on hotplug event.





                          share|improve this answer



























                            1












                            1








                            1







                            The easiest and right way to do this is by editing /etc/network/interfaces.



                            Here is a simple example of /etc/network/interfaces:



                            auto lo eth0
                            iface lo inet loopback

                            allow-hotplug eth0
                            iface eth0 inet dhcp
                            metric 700


                            Restart networking using service networking restart for the changes to take place.



                            Ref: Section 5.7.2. The ifmetric package of Debian Manual




                            The following sets the eth0 interface to be preferred over the wlan0
                            interface.



                            Install the ifmetric package.



                            Add an option line with "metric 0" just below the "iface eth0 inet
                            dhcp" line in "/etc/network/interfaces".



                            Add an option line with "metric 1" just below the "iface wlan0 inet
                            dhcp" line in "/etc/network/interfaces".




                            Extra Note:




                            • auto <interface1> <interface2> starts interfaces on start of the system.


                            • allow-hotplug <interface> starts the interface on hotplug event.





                            share|improve this answer















                            The easiest and right way to do this is by editing /etc/network/interfaces.



                            Here is a simple example of /etc/network/interfaces:



                            auto lo eth0
                            iface lo inet loopback

                            allow-hotplug eth0
                            iface eth0 inet dhcp
                            metric 700


                            Restart networking using service networking restart for the changes to take place.



                            Ref: Section 5.7.2. The ifmetric package of Debian Manual




                            The following sets the eth0 interface to be preferred over the wlan0
                            interface.



                            Install the ifmetric package.



                            Add an option line with "metric 0" just below the "iface eth0 inet
                            dhcp" line in "/etc/network/interfaces".



                            Add an option line with "metric 1" just below the "iface wlan0 inet
                            dhcp" line in "/etc/network/interfaces".




                            Extra Note:




                            • auto <interface1> <interface2> starts interfaces on start of the system.


                            • allow-hotplug <interface> starts the interface on hotplug event.






                            share|improve this answer














                            share|improve this answer



                            share|improve this answer








                            edited Feb 4 at 22:04

























                            answered Feb 4 at 21:23









                            Jithin PavithranJithin Pavithran

                            1487




                            1487



























                                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%2f344974%2fhow-can-i-make-changes-to-the-network-routing-metric-permanently%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

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

                                Displaying single band from multi-band raster using QGIS

                                How many registers does an x86_64 CPU actually have?