# Help! Routing between openvpn server and local network

## sglorz

Hello,

I have two connections on my server:

1/ first is eth0 with a local IP connected to my router and then my ISP.

2/ second is tun0 connected to a VPN server.

But, I want to have all the traffic redirected to my eth0 except for some ports (like ssh/22 or http/8080) that I want to be redirected to tun0.

Actually, when I start the openvpn client all traffic is redirected to tun0. So, it seems that I need to add a route instruction in my VPN client conf, but I don't know how.

So, could someone help me to configure that?

Thanks

----------

## mikegpitt

I believe this link describes what you are looking for:

http://wiki.debian.org/HowTo/openvpn

Look at the section toward the bottom that describes configuring the VPN server as a pass through proxy.

----------

## sglorz

Thank you for your answer, but I don't think it will help me as I'm connecting to a VPN server that I don't manage.

I think I will look into net filter with iptables.

----------

## mikegpitt

 *sglorz wrote:*   

> Thank you for your answer, but I don't think it will help me as I'm connecting to a VPN server that I don't manage.

 That might be a problem.  If the VPN server isn't configured as a proxy, then you won't be able to use it in such a way.  Sure, you can route all your eth0 traffic to the VPN server, but it won't know what to do with it.

----------

## sglorz

Ok I see. 

But, I have two interfece: one is lan eth0 and this other is VPN tun0. 

So, is it possible to tell my Gentoo to send all the local trafic to eth0 except for some port to tun0?

----------

## mikegpitt

I believe the route commands at the bottom of the link I posted before do this.  I haven't tested it myself, but it looks like it should work:

```
route del default eth0

route add default gw 10.9.8.1 dev tun0
```

It should also be possible with iptables.  Again, I haven't tested this... but something like this should work:

```
echo "1" > /proc/sys/net/ipv4/ip_forward

iptables -t nat -A PREROUTING -p tcp -i eth0 -j DNAT

iptables -A FORWARD -i eth0 -o tun0 -p tcp -j ACCEPT
```

----------

## sglorz

Thank you, I shall look into this.

----------

