Only start OpenVPN if not on “home” LAN
This bash script only starts the OpenVPN client if the client PC is not connected to the “home” LAN. IE The LAN where the OpenVPN Server resides.
This is useful for machines such as an offsite backup server which could be occasionally moved into the office where the OpenVPN server is located.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# Start OpenVPN # Replace the address below with the broadcast address of the server's subnet SERVERBCAST="192.168.1.255" IP=`ifconfig eth0 | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'` BROADCAST=`ifconfig eth0 | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f3 | awk '{ print $1}'` NETMASK=`ifconfig eth0 | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f4 | awk '{ print $1}'` echo " * IP $IP Netmask $NETMASK Broadcast $BROADCAST" if [ "$BROADCAST" != "$SERVERBCAST" ]; then echo " * Starting OpenVPN" /usr/local/sbin/openvpn --config /etc/openvpn/client.conf --daemon else echo " * Not Starting OpenVPN - Already on server's subnet." fi |