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 dev eth1 table net2
ip rule add from table net2
ip rule add to 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 dev eth1 table net2
post-up ip rule add from table net2
post-up ip rule add to 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).

  • 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 '18 at 19:36

Edit the static routes file in /etc/conf.d/staticroute

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

rc-update add staticroute

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.