Last active
November 3, 2022 12:18
-
-
Save dzianisv/f24029c53454e1723d272875aae325bb to your computer and use it in GitHub Desktop.
OpenWRT setup vpn routing script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh /etc/rc.common | |
| START=90 | |
| USE_PROCD=1 | |
| PROG=/usr/bin/setup-vpn-routing | |
| start_service() { | |
| procd_open_instance setup-vpn-routing | |
| procd_set_param command "$PROG" | |
| procd_close_instance | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| isolate_vpn() { | |
| if ! ip rule show | grep "from 192.168.42.0/24"; then | |
| ip rule add from 192.168.42.0/24 table vpnlan | |
| fi | |
| if ! ip route show table vpnlan | grep "default via 10.0.0.1"; then | |
| ip route add default via 10.0.0.1 table vpnlan | |
| fi | |
| } | |
| route_via_uplink() { | |
| UPLINK_GW=192.168.100.1 | |
| if ! ip route show | grep "default via $UPLINK_GW"; then | |
| ip route del default | |
| ip route add default via $UPLINK_GW | |
| fi | |
| } | |
| loop() { | |
| while :; do | |
| isolate_vpn | |
| route_via_uplink | |
| sleep 5 | |
| done | |
| } | |
| loop |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment