OpenVPN Derouting

From WikiHistedOrg

Jump to: navigation, search

If OpenVPN is set up to route everything through the VPN, you can reset the routes on your client machine to route only subnet traffic through it.

You need to use route.exe to delete the default route (0.0.0.0 MASK 0.0.0.0) and replace it with your normal subnet's gateway.

On Windows with Cygwin I use the script below. I'm sure there's a way to do this with Windows scripting host or batch files, but I don't know how.


#!/bin/sh

route print | grep -q -E '^ *0.0.0.0' 
if [ $? -eq 0 ]; then
    # def route found, delete it
    route DELETE 0.0.0.0
fi

defGateway=`route print | grep Default | tee | awk '{print $3}'`
if [ "$defGateway"a == a ]; then
    # defGatway not found.  Try to sniff it out
    defGateway=`route print | grep -E '^ *18.93.3.229 ' | awk '{print $3}'`
fi
route add 0.0.0.0 mask 0.0.0.0 $defGateway