Created
November 17, 2025 18:49
-
-
Save Snawoot/7e6eafb390931a08135b71e93dbb8202 to your computer and use it in GitHub Desktop.
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/bash -x | |
| INTERFACE="$1" | |
| DEVICE="$2" | |
| SPEED="$3" | |
| LOCALIP="$4" | |
| REMOTEIP="$5" | |
| IPPARAM="$6" | |
| if [[ "$IPPARAM" != "vpn" ]] ; then | |
| # not our config | |
| exit 0 | |
| fi | |
| PROTECT=("vps.example.org") # preserve route for these addresses | |
| default_route4=$(ip -4 route show default | head -1 | cut -d\ -f2-) | |
| default_route6=$(ip -6 route show default | head -1 | cut -d\ -f2-) | |
| for protect_address in "${PROTECT[@]}"; do | |
| >&2 echo "Protecting $protect_address..." | |
| if [[ "$default_route4" ]]; then | |
| for ip in $(getent ahostsv4 "$protect_address" | cut -f1 -d\ | sort | uniq); do | |
| ip -4 route replace "$ip" $default_route4 | |
| done | |
| fi | |
| if [[ "$default_route6" ]]; then | |
| for ip in $(getent ahostsv6 "$protect_address" | cut -f1 -d\ | sort | uniq); do | |
| ip -6 route replace "$ip" $default_route6 | |
| done | |
| fi | |
| done | |
| ip -4 route replace 0.0.0.0/1 dev "$INTERFACE" | |
| ip -4 route replace 128.0.0.0/1 dev "$INTERFACE" | |
| # prevent ipv6 leaks | |
| ip -6 route replace unreachable 2000::/3 | |
| # workaround bug https://lists.opensuse.org/archives/list/bugs@lists.opensuse.org/thread/ZHDF667RJDGAEWJCJB7HGWNARKLAIPGK/ | |
| #if [[ "$DNS1" ]]; then | |
| # resolvconf="/var/run/ppp/resolv.conf.$INTERFACE" | |
| # chattr -i "$resolvconf" | |
| # echo "nameserver $DNS1" > "$resolvconf" | |
| # if [[ "$DNS2" ]]; then | |
| # echo "nameserver $DNS2" >> "$resolvconf" | |
| # fi | |
| # chmod 0644 "$resolvconf" | |
| # chattr +i "$resolvconf" | |
| # mount --bind --onlyonce "$resolvconf" /etc/resolv.conf | |
| #fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment