How to use vpn for specific domains?

How to customize and extend your OpenVPN installation.

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

Post Reply
Sollembum78
OpenVpn Newbie
Posts: 3
Joined: Tue Jun 06, 2017 7:10 pm

How to use vpn for specific domains?

Post by Sollembum78 » Tue Jun 06, 2017 7:29 pm

Main question: How to route all traffic without vpn, and only specific domains or ips with vpn?

All traffic BYPASS VPN, and certain sites routed through vpn

Hello. I'm noob in all this vpn stuff, but I got reasons to use it, as some sites are not accessible directly, without vpn.

I setup openvpn server on my ovh dedicated machine (using simple script by nyr) and now using client for windows I can use openvpn with almost no problems. But, speed isn't always the best, with vpn download speed may be 2MB/s, but without 10-15MB/s, so I got reason to ask, how do I route only certain traffic through vpn?

There are a lot of discussions on how to route all with vpn, and specific site without, but my question of opposite, how to route all without vpn, and certain sites with? I want to do this by editing client-side config. I saw some people write it's possible, but everytime I try something, it doesn't connect at all.

Can someone provide few lines I need to add to config for this? Like
route blockedsite.com vpn
route alltraffic notvpn

P.S. Minor problem. When I disconnect from openvpn and try to connect next day it doesn't connect, so I have to restart server side with "sudo service openvpn restart", and then it works. I'm running xubuntu 14.04 on server.

TinCanTech
OpenVPN Protagonist
Posts: 11137
Joined: Fri Jun 03, 2016 1:17 pm

Re: How to use vpn for specific domains?

Post by TinCanTech » Wed Jun 07, 2017 12:06 pm

Sollembum78 wrote:All traffic BYPASS VPN, and certain sites routed through vpn
Sollembum78 wrote:Can someone provide few lines I need to add to config for this? Like
route blockedsite.com vpn
route alltraffic notvpn
Like so
  • Remove all --redirect-gateway options from server and client
  • Add routes for domain to use VPN either pushed from server or in client config
    eg:
    server
    route 10.11.12.0 255.255.255.0
    push "route 10.11.12.0 255.255.255.0"
    or
    server
    route 10.11.12.0 255.255.255.0
    client
    route 10.11.12.0 255.255.255.0
If you mean to route something like my.domain.org, I don't recommend this but like so:
  • client
    route my.domain.org
There are other steps you need to ensure things work like using iptables to NAT your client packets.
Please read the howto.

Sollembum78 wrote:P.S. Minor problem. When I disconnect from openvpn and try to connect next day it doesn't connect, so I have to restart server side with "sudo service openvpn restart", and then it works. I'm running xubuntu 14.04 on server.
Please see:
HOWTO: Request Help !

Sollembum78
OpenVpn Newbie
Posts: 3
Joined: Tue Jun 06, 2017 7:10 pm

Re: How to use vpn for specific domains?

Post by Sollembum78 » Tue Jun 20, 2017 11:26 am

Hello, sorry for late response. What are exactly those numbers? I tried to write this:
route 10.11.12.0 255.255.255.0
On both client and server and when I use openvpn this way, it connects to nothing, sites don't open, only my vpn hosting is accesible. Is it suppose to be some exact number, or maybe ip of website I need to access or what? I believe 255.. is like, what network to use, and 10.11.. is what?

TinCanTech
OpenVPN Protagonist
Posts: 11137
Joined: Fri Jun 03, 2016 1:17 pm

Re: How to use vpn for specific domains?

Post by TinCanTech » Tue Jun 20, 2017 12:41 pm

The numbers in my post are an example only !

I don't know what you want to route via the VPN so how would I know the numbers .. ?

Sollembum78
OpenVpn Newbie
Posts: 3
Joined: Tue Jun 06, 2017 7:10 pm

Re: How to use vpn for specific domains?

Post by Sollembum78 » Fri Jun 23, 2017 2:28 pm

TinCanTech wrote:The numbers in my post are an example only !

I don't know what you want to route via the VPN so how would I know the numbers .. ?
So, this numbers are ips of websites which I get from dns?

Post Reply