Home » Questions » Computers [ Ask a new question ]

How to selectively route network traffic through VPN on Mac OS X Leopard?

How to selectively route network traffic through VPN on Mac OS X Leopard?

I don't want to send all my network traffic down to VPN when I'm connected to my company's network (via VPN) from home. For example, when I'm working from home, I would like to be able to backup all my files to the Time Capsule at home and still be able to access the company's internal network.

Asked by: Guest | Views: 337
Total answers/comments: 2
Guest [Entry]

"Create the file /etc/ppp/ip-up with following content:

#!/bin/sh
/sbin/route add <SUBNET> -interface $1

replacing <SUBNET> with subnet, you want to route through VPN (for ex. 192.168.0.0/16)

execute as root:

chmod 0755 /etc/ppp/ip-up

This file will be executed each time you connect to VPN.

The parameters given to the script:

$1: The VPN interface (e.g. ppp0)
$2: Unknown, was 0 in my case
$3: IP of the VPN server
$4: VPN gateway address
$5: Regular (non-vpn) gateway for your lan connections"
Guest [Entry]

"I wanted to do a similar thing. Connect the VPN and then route an additional network via that VPN. I ended up with the following bit of Applescript:

-- Connect Work VPN

tell application ""System Events""
tell network preferences
tell current location
tell service ""Work""
connect
tell current configuration
repeat until get connected = true
delay 1
end repeat
end tell
end tell
end tell
end tell
end tell

set gateway to ""192.168.1.1""

do shell script ""route add 172.16.0.0/16 "" & gateway with administrator privileges

You need to change ""Work"" to the name of your VPN connection, 192.168.1.1 to your gateway address, and 172.16.0.0/16 to the address of the network to which you wish to route. Additional networks can be added by repeating the final line with different addresses."