From 7602aae2a0de650683779d49099585a3836e6238 Mon Sep 17 00:00:00 2001 From: gaoyuheng Date: Mon, 26 Jan 2026 12:00:37 +0800 Subject: [PATCH] =?UTF-8?q?=E8=81=94=E5=8A=A8=20IPrule=E8=A7=84=E5=88=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ip-policy-rules | 47 +++++++++++++++++++++++++++++++++++++++++++++++ update.sh | 4 ++++ 2 files changed, 51 insertions(+) create mode 100644 ip-policy-rules diff --git a/ip-policy-rules b/ip-policy-rules new file mode 100644 index 0000000..a4a4607 --- /dev/null +++ b/ip-policy-rules @@ -0,0 +1,47 @@ +#!/sbin/openrc-run + +description="Custom IP Policy Route Rules for Alpine" + +depend() { + need net networking + after net-online + trigger on restart networking +} + +trigger() { + case "$1" in + restart) + ebegin "Triggered by networking restart, reloading IP policy rules" + restart + eend $? + ;; + *) + ebegin "Unsupported trigger: $1" + eend 1 + ;; + esac +} + +start() { + ebegin "Loading custom IP policy rules" + ip rule add from 44.32.191.0/24 to 0.0.0.0/0 lookup 102 priority 200 + ip rule add from 172.20.0.0/14 to 172.20.0.0/14 lookup 105 priority 300 + ip -6 rule add from 2000::/3 to 2000::/3 lookup 102 priority 200 + ip -6 rule add from fd00::/8 to fd00::/8 lookup 105 priority 300 + eend $? "Failed to load IP policy rules" +} + +stop() { + ebegin "Removing custom IP policy rules" + ip rule del from 44.32.191.0/24 to 0.0.0.0/0 lookup 102 priority 200 + ip rule del from 172.20.0.0/14 to 172.20.0.0/14 lookup 105 priority 300 + ip -6 rule del from 2000::/3 to 2000::/3 lookup 102 priority 200 + ip -6 rule del from fd00::/8 to fd00::/8 lookup 105 priority 300 + eend $? "Failed to remove IP policy rules" +} + +restart() { + stop + sleep 1 + start +} \ No newline at end of file diff --git a/update.sh b/update.sh index fde1a43..80b25c0 100644 --- a/update.sh +++ b/update.sh @@ -37,6 +37,10 @@ rm /etc/bird/conf/inet_ixp.conf -f echo " 105 dn42" >> /etc/iproute2/rt_tables +mv ./bird_config/ip-policy-rules /etc/init.d/ip-policy-rules +chmod +x /etc/init.d/ip-policy-rules +rc-update add ip-policy-rules default +rc-service ip-policy-rules start chmod -R 755 /etc/bird