# How to use vpn only for a spedific host?

## lowsfer

I got a vpn tunnel from my wlan0 interface to a vpn server. The interface is tun0. After setting up tun0, all network data goes via tun0 by default.

Now I want to use tun0 only for visiting an numerical workstation "phonon", while all other network data goes via wlan0 directly. How should I do that? iptables, or routing? I'm no expert in iptables or route table.

Thanks.

----------

## Yuu

Hi lowsfer,

as far as I know, OpenVPN's behavior depends on his configuration file (/etc/openvpn/<vpn-name>.conf).

If you have something like "redirect-gateway def1 bypass-dhcp" in your configuration file, it's totaly normal that the tun0 interface become the default routing interface :

 *man openvpn or http://openvpn.net/index.php/open-source/documentation/manuals/69-openvpn-21.html wrote:*   

> --redirect-gateway flags...
> 
>     (Experimental) Automatically execute routing commands to cause all outgoing IP traffic to be redirected over the VPN.
> 
>     This option performs three steps:
> ...

 

So, you shoud just have to do something like : remove the default route to the vpn : route del default tun0

add the default route to your standard interface : route add default wlan0

create a new route to the VPN with table 200 : ip route add default add <gateway of your VPN here> table 200

phonon workstation connections should follow the VPN route : ip rule add  from <your phonon workstation here> table 200

enable masquerading on the VPN interface : iptables -A POSTROUTING -t nat -o tun0 -j MASQUERADE

Maybe those lines need more modifications : I've written them without testing. Also, you could use the openvpn up/down scripts to automatically do the job. Oh, and I strongly advise you to read the openvpn's manual :]

Good luck~

----------

## lowsfer

Hi Yuu,

I have been using vpnc. I will check openvpn.

Thank you very much!

 *Yuu wrote:*   

> Hi lowsfer,
> 
> as far as I know, OpenVPN's behavior depends on his configuration file (/etc/openvpn/<vpn-name>.conf).
> 
> If you have something like "redirect-gateway def1 bypass-dhcp" in your configuration file, it's totaly normal that the tun0 interface become the default routing interface :
> ...

 

----------

