Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Goal: To selectively route traffic over a VPN, so that general browsing/downloads goes via the normal primary connection, with my business VPN traffic going over the VPN.

I have tried a similar method mentioned here, but no matter how I changed the details it didn't work.

The VPN works, I can connect and route all traffic over it, so that is not the issue.

Home IP: 192.168.34.X

IP from VPN: 192.168.1.X

IP's (via VPN) trying to access in the internal network: 10.4.X.X, 196.220.X.X

How to selectively route traffic for one specified IP adddress through the VPN tunnel (not all traffic)?

share|improve this question
    
Shame I cannot comment for some reason --- this is not an answer but a follow-up. So before deleting it, please see my question here: apple.stackexchange.com/questions/96071/… I would like to route my VM traffic (or just some specific public IPs) over my PPTP VPN, but (maybe because my settings are not manual) I cannot figure out the specifics. Thanks! –  László Jul 10 '13 at 22:04
add comment

1 Answer

Step 1, create two plain text files: ip-up and ip-down in /etc/ppp, make the two files executable (chmod +x)

Step 2, modify the ip-up, add the following:

#!/bin/sh
export PATH="/bin:/sbin:/usr/sbin:/usr/bin"

OLDGW=`netstat -nr | grep '^default' | grep -v 'ppp' | sed 's/default *\([0-9\.]*\) .*/\1/'`

if [ ! -e /tmp/pptp_oldgw ]; then
    echo "${OLDGW}" > /tmp/pptp_oldgw
fi

dscacheutil -flushcache
route add 10.4.0.0/24 "${OLDGW}"

Step 3, modify the ip-down, add the following:

#!/bin/sh
export PATH="/bin:/sbin:/usr/sbin:/usr/bin"

if [ ! -e /tmp/pptp_oldgw ]; then
        exit 0
fi

ODLGW=`cat /tmp/pptp_oldgw`

route delete 10.4.0.0/24 "${OLDGW}"
rm /tmp/pptp_oldgw
share|improve this answer
    
Tried this exactly as you outlined - it did not work. Still not able to access either of the webpages via the VPN only while other browsing is via default connection. Any further thoughts? –  Nate Kettles Aug 7 '12 at 19:39
    
The script is selectively not route traffic for specific IP. Other than those IP, all route via VPN. ip-up runs when you connect to VPN, the specific IP will add to your old route table (so not going through VPN). ip-down runs when you disconnect from VPN. –  kukoo Aug 8 '12 at 0:57
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.