How to persist iproute2 routes and rules in Alpine Linux?












0














I'm trying to persist (between reboots) routes and rules from iproute2 in Alpine Linux, so far without success.



Here are the commands:



ip route add default via 192.168.200.1 dev eth1 table net2
ip rule add from 192.168.200.10/24 table net2
ip rule add to 192.168.200.1/32 table net2


So the proper way to do this should be theoretically by using the "post-up" callback in the "/etc/network/interfaces" file in the eth1 interface. So I added these lines to the interface:



post-up route add default via 192.168.200.1 dev eth1 table net2
post-up ip rule add from 192.168.200.10/24 table net2
post-up ip rule add to 192.168.200.1/32 table net2


But it doesn't works. It seems like the callback is never run. The same goes with "up". I tried a simple "touch /tmp/ok" and the file gets never created.



Alternatively I tried creating a script inside the "/etc/network/if-post-up.d" but the script gets called for every interface that goes up, resulting in repeated entries in the rules. What would be the right way to make this work properly (With that I mean run the rule only once when the interface goes up, and undo the rules when it goes down).










share|improve this question


















  • 1




    Alpine is a very cut down distribution, and some of the rules of Debian might not apply. The if-post-xxxx might also be a construct of a particular DHCP client.
    – Rui F Ribeiro
    Dec 8 at 19:36
















0














I'm trying to persist (between reboots) routes and rules from iproute2 in Alpine Linux, so far without success.



Here are the commands:



ip route add default via 192.168.200.1 dev eth1 table net2
ip rule add from 192.168.200.10/24 table net2
ip rule add to 192.168.200.1/32 table net2


So the proper way to do this should be theoretically by using the "post-up" callback in the "/etc/network/interfaces" file in the eth1 interface. So I added these lines to the interface:



post-up route add default via 192.168.200.1 dev eth1 table net2
post-up ip rule add from 192.168.200.10/24 table net2
post-up ip rule add to 192.168.200.1/32 table net2


But it doesn't works. It seems like the callback is never run. The same goes with "up". I tried a simple "touch /tmp/ok" and the file gets never created.



Alternatively I tried creating a script inside the "/etc/network/if-post-up.d" but the script gets called for every interface that goes up, resulting in repeated entries in the rules. What would be the right way to make this work properly (With that I mean run the rule only once when the interface goes up, and undo the rules when it goes down).










share|improve this question


















  • 1




    Alpine is a very cut down distribution, and some of the rules of Debian might not apply. The if-post-xxxx might also be a construct of a particular DHCP client.
    – Rui F Ribeiro
    Dec 8 at 19:36














0












0








0







I'm trying to persist (between reboots) routes and rules from iproute2 in Alpine Linux, so far without success.



Here are the commands:



ip route add default via 192.168.200.1 dev eth1 table net2
ip rule add from 192.168.200.10/24 table net2
ip rule add to 192.168.200.1/32 table net2


So the proper way to do this should be theoretically by using the "post-up" callback in the "/etc/network/interfaces" file in the eth1 interface. So I added these lines to the interface:



post-up route add default via 192.168.200.1 dev eth1 table net2
post-up ip rule add from 192.168.200.10/24 table net2
post-up ip rule add to 192.168.200.1/32 table net2


But it doesn't works. It seems like the callback is never run. The same goes with "up". I tried a simple "touch /tmp/ok" and the file gets never created.



Alternatively I tried creating a script inside the "/etc/network/if-post-up.d" but the script gets called for every interface that goes up, resulting in repeated entries in the rules. What would be the right way to make this work properly (With that I mean run the rule only once when the interface goes up, and undo the rules when it goes down).










share|improve this question













I'm trying to persist (between reboots) routes and rules from iproute2 in Alpine Linux, so far without success.



Here are the commands:



ip route add default via 192.168.200.1 dev eth1 table net2
ip rule add from 192.168.200.10/24 table net2
ip rule add to 192.168.200.1/32 table net2


So the proper way to do this should be theoretically by using the "post-up" callback in the "/etc/network/interfaces" file in the eth1 interface. So I added these lines to the interface:



post-up route add default via 192.168.200.1 dev eth1 table net2
post-up ip rule add from 192.168.200.10/24 table net2
post-up ip rule add to 192.168.200.1/32 table net2


But it doesn't works. It seems like the callback is never run. The same goes with "up". I tried a simple "touch /tmp/ok" and the file gets never created.



Alternatively I tried creating a script inside the "/etc/network/if-post-up.d" but the script gets called for every interface that goes up, resulting in repeated entries in the rules. What would be the right way to make this work properly (With that I mean run the rule only once when the interface goes up, and undo the rules when it goes down).







iproute alpine-linux






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Dec 8 at 19:34









Robert Koszewski

355




355








  • 1




    Alpine is a very cut down distribution, and some of the rules of Debian might not apply. The if-post-xxxx might also be a construct of a particular DHCP client.
    – Rui F Ribeiro
    Dec 8 at 19:36














  • 1




    Alpine is a very cut down distribution, and some of the rules of Debian might not apply. The if-post-xxxx might also be a construct of a particular DHCP client.
    – Rui F Ribeiro
    Dec 8 at 19:36








1




1




Alpine is a very cut down distribution, and some of the rules of Debian might not apply. The if-post-xxxx might also be a construct of a particular DHCP client.
– Rui F Ribeiro
Dec 8 at 19:36




Alpine is a very cut down distribution, and some of the rules of Debian might not apply. The if-post-xxxx might also be a construct of a particular DHCP client.
– Rui F Ribeiro
Dec 8 at 19:36










1 Answer
1






active

oldest

votes


















0














Edit static routes in /etc/conf.d/staticroutes



Ensure staticroutes starts at boot time in order to reload those configs, with:



rc-update add staticroutes





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%2f486834%2fhow-to-persist-iproute2-routes-and-rules-in-alpine-linux%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Edit static routes in /etc/conf.d/staticroutes



    Ensure staticroutes starts at boot time in order to reload those configs, with:



    rc-update add staticroutes





    share|improve this answer




























      0














      Edit static routes in /etc/conf.d/staticroutes



      Ensure staticroutes starts at boot time in order to reload those configs, with:



      rc-update add staticroutes





      share|improve this answer


























        0












        0








        0






        Edit static routes in /etc/conf.d/staticroutes



        Ensure staticroutes starts at boot time in order to reload those configs, with:



        rc-update add staticroutes





        share|improve this answer














        Edit static routes in /etc/conf.d/staticroutes



        Ensure staticroutes starts at boot time in order to reload those configs, with:



        rc-update add staticroutes






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Dec 13 at 9:38

























        answered Dec 13 at 8:45









        garethTheRed

        23.9k36079




        23.9k36079






























            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%2f486834%2fhow-to-persist-iproute2-routes-and-rules-in-alpine-linux%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