Help with routing after client connection

How to customize and extend your OpenVPN installation.

Moderators: TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech

Post Reply
guidx
OpenVpn Newbie
Posts: 2
Joined: Tue Apr 12, 2011 4:16 pm

Help with routing after client connection

Post by guidx » Tue Apr 12, 2011 4:22 pm

Hi, i have a question about routing and OpenVPN.

I have an OpenVPN server account from a provider that I use as a VPN-solution. I have no control over the OpenVPN-server. I use Tunnelblick on OSX but I believe this is a pretty generic OpenVPN question. The server pushes some settings to my client and amongst other stuff it sends the "redirect-gateway def1" command which prevents OpenVPN from changing my default gateway but instead adds more specific routes so that my internet connection always uses the OpenVPN-server. So far so good.

Connected to the server, a netstat -nr returns this:

0/1 10.9.0.1 UGSc 18 0 tun0
default 192.168.10.1 UGSc 2 0 en1
10.9/16 10.9.0.68 UGSc 28 0 tun0
10.9.0.68 10.9.0.68 UH 2 0 tun0

192.168.10.1 is my ordinary gateway and 10.9.0.1 is the OpenVPN-gateway.

What I want to configure is this:

When i connect to the OpenVPN server I want to let all my traffic keep flowing through my ordinary gateway 192.168.10.1 and only add routes for a few specific sites that should go trough the VPN. The VPN-tunnel should be connected but only used for routing to specific sites.

I know this can be accomplished by changing the routes in OSX terminal manually but i want the OpenVPN client to do it automatically after connecting so I dont have to think about it.

I guess what i want is to change the routing of 0/1 from 10.9.0.1 to 192.168.10.1 in OpenVPN after connecting to the server. Or remove it should also work i presume since OSX would then use the standard gateway instead (which is still 192.168.10.1 because of the redirect-gateway def1-command. If I have gotten how it works correctly ;-D

Thankful for any help in the right direction!

Regards
Gunnar Netsedi

User avatar
janjust
Forum Team
Posts: 2703
Joined: Fri Aug 20, 2010 2:57 pm
Location: Amsterdam
Contact:

Re: Help with routing after client connection

Post by janjust » Tue Apr 12, 2011 4:37 pm

use

Code: Select all

route-nopull
to stop pulling the routes from the openvpn server; then add the routes that you want routed via the VPN to the client config file using

Code: Select all

route a.b.c.d netmask1
route e.f.g.h netmask2 
etc.

guidx
OpenVpn Newbie
Posts: 2
Joined: Tue Apr 12, 2011 4:16 pm

Re: Help with routing after client connection

Post by guidx » Tue Apr 12, 2011 7:13 pm

Thanks! Worked great.

Post Reply