MacOS – Routing all traffic except a few IP-ranges though default gateway in Mountain Lion

macososx-mountain-lionvpn

I am using VPN (Cisco IPSec) through the default Mountain Lion network preferences. In Lion (and also i Snow Leopard), I did the following to change the routing back to using my default gateway for all traffic, and the set up a few routes for the specific IP-ranges that needed to go through VPN:

# Route traffic through VPN:
route -nv add -net IPRANGE -interface utun0
#...more lines for the different IP-ranges that should go through VPN)

# Route all other traffic through the old default gateway:
route change default DEFAULT-GATEWAY-IP

This seems to not work under Mountain Lion. The (new implementation?) of Cisco IPSec seems to dynamically add a lot of routes to the routing table as I visit them in the browser.

I have debugged this a lot (pinging, traceroute'ing), but still haven't found a solution.

The basic problem I'm trying to solve is just to route traffic for specific IP-ranges through VPN, everything else should act as I am not connected to VPN. Any other solution that achieves that will be fine with me =)

Best Answer

If you specify in the VPN preference panel (System Preferences, VPN item, Advanced) that you do NOT want all traffic routed through the VPN, then after connecting to the VPN, none of your routes will be altered. Then, to get routes just for the specific things you need that are on the inside of the VPN, you need to create this file:

/etc/ppp/ip-up

containing

#!/bin/bash
/sbin/route add -net 10.10.10 -interface ppp0

where "10.10.10" corresponds to the subnet of where you are inside. The above works when I want to get into the 10.10.10/24 network, whose subnet is 255.255.255.0. If the subnet was 255.255.0.0, I would substitute "10.10" instead.

When you made the file, set its permissions so it will run after the VPN connects:

chmod 755 /etc/ppp/ip-up 

I don't know what to tell you if you have multiple VPNs that you need to connect to, each with different routes that need to be added. But this works for just 1 VPN.

Related Question