In my init.d script for vpnclient I have to set a route to the VPN server's public IP.. At the moment I have 10+ VPN servers so its a PITA and having to make 10+ extra routes... I figured out how to find the default interface's local IP with a variable script. But I have to repeat it for every VPN server I have.... The example below is only for two VPN servers but you get the idea.... Just thinking there has to be a better way.
55.55.55.55 & 66.66.66.66=VPN Server's Public IP's
Code: Select all
#! /bin/sh
#######################################################
### SoftEther Client
#######################################################
### BEGIN INIT INFO
# Provides: vpnclient
# Required-Start: $all
# Required-Stop: $network $local_fs $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start VPN Client at boot time
# chkconfig: 345 44 56
# description: Start VPN Client at boot time.
# processname: vpnclient
# 55.55.55.55 = VPN public IP
### END INIT INFO
# /etc/init.d/vpnclient
###########################
case "$1" in
start)
echo "Starting VPN Client"
/usr/local/vpnclient/vpnclient start
sleep 1
if ifconfig -a | grep vpn_soft >/dev/null
then
echo "Setting up vpn_soft..."
else
echo "Interface vpn_soft not found" &1>2
ifdown vpn_soft
sleep 1
ifup vpn_soft
sleep 1
echo "Setting up vpn_soft..."
exit 1
fi
route add -host 55.55.55.55 gw $(ip route list exact 0.0.0.0/0 | grep wlan0 | xargs | awk '{print $3}')
route add -host 66.66.66.66 gw $(ip route list exact 0.0.0.0/0 | grep wlan0 | xargs | awk '{print $3}')
/usr/local/vpnclient/./vpncmd
;;
stop)
echo "Stopping VPN Client"
/usr/local/vpnclient/vpnclient stop
route del -host 55.55.55.55
route del -host 66.66.66.66
route add default gw $(ip route list exact 0.0.0.0/0 | grep wlan0 | xargs | awk '{print $3}') dev wlan0
;;
*)
echo "Usage: /etc/init.d/vpnclient {start|stop}"
exit 1
;;
esac
exit 0
With DHCP in /etc/network/interfaces
Code: Select all
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
auto-hotplug vpn_soft
iface vpn_soft inet dhcp