Created
February 5, 2014 16:46
-
-
Save markosamuli/8827942 to your computer and use it in GitHub Desktop.
vpn-route-add
This file contains 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 | |
SCRIPT=$(basename $0) | |
if [[ $EUID -ne 0 ]]; then | |
echo "This script must be run as root" | |
exit 1 | |
fi | |
TARGET_HOST=$1 | |
if [ -z "$TARGET_HOST" ]; then | |
echo "Target hostname missing" | |
echo "Usage: $SCRIPT <hostname>" | |
exit 1 | |
fi | |
# VPN interface (update this) | |
VPN_IF=gpd0 | |
VPN_IP=$(ifconfig | grep $VPN_IF -A2 | grep "inet" | awk '{print $2}') | |
if [ -z "$VPN_IP" ]; then | |
echo "Failed to resolve VPN gateway IP address" | |
exit 1 | |
fi | |
# Get all IP addresses for this hostname | |
TARGET_IPS=$(host $TARGET_HOST | grep "has address" | awk '{print $4}' | xargs) | |
# Add routes to all of these addresses | |
echo "VPN gateway IP: $VPN_IP" | |
for IP in $TARGET_IPS; do | |
route add $IP $VPN_IP | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment