Last active
August 13, 2023 16:12
-
-
Save acheong08/d638233a7bbb7ab37fba7a773bf82b63 to your computer and use it in GitHub Desktop.
Linux script to allow certain IPs to bypass VPN
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 | |
if [ "$EUID" -ne 0 ]; then | |
echo "This script must be run as root." | |
exit 1 | |
fi | |
if [ "$#" -lt 1 ]; then | |
echo "Usage: sudo tunbypass <add/del/list> [server_ip]" | |
exit 1 | |
fi | |
action="$1" | |
gateway=$(ip route | grep default | awk '{print $3}') | |
default_interface=$(ip route | grep default | awk '{print $5}') | |
if [ "$action" == "list" ]; then | |
echo "Bypassed Server IPs:" | |
ip route | grep "via $gateway" | grep "metric 10" | awk '{print $1}' | |
exit 0 | |
fi | |
if [ "$#" -ne 2 ]; then | |
echo "Usage: sudo tunbypass <add/del/list> [server_ip]" | |
exit 1 | |
fi | |
server_ip="$2" | |
if [ "$action" == "add" ]; then | |
sudo ip route add "$server_ip" via "$gateway" dev "$default_interface" metric 10 | |
echo "Added bypass for $server_ip." | |
elif [ "$action" == "del" ]; then | |
sudo ip route del "$server_ip" via "$gateway" dev "$default_interface" metric 10 | |
echo "Removed bypass for $server_ip." | |
else | |
echo "Invalid action. Use 'add', 'del', or 'list'." | |
exit 1 | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment