OpenWrt Forum Archive

Topic: policy based routing with OpenVPN

The content of this topic has been archived on 30 Mar 2018. There are no obvious gaps in this topic, but there may still be some posts missing at the end.

I currently am using an Asus RT-N56U and it has been doing a decen job for me.  I have been using Padavan's custom firmware and that coupled with a very long IPtables script provides some policy based routing for me based on IP address.

Recently I have been having some weird behavior, and before looking into a new router I wanted to try some new firmware.  I was hoping that my next router would have some easy routing options for openvpn.  I have seen some on other firmwares but OpenWRT seems to have the best compatibility and so far, the easiest place to navigate.

How difficult is it to perform IP based routing in OperWRT 15.05 (or higher)?  Currently I have x.x.x.1 - x.x.x.100 going through VPN, while everything above .100 goes through my WAN.

Thanks for your time! I Hope that all made sense

Hi,

I struggled with the same problem.

The solution was:

Create an up and down script, which are involved by the OpenVPN process:

Add

  
route-nopull
route-noexec
up /etc/openvpn/cg/up-script.sh
down /etc/openvpn/cg/down-script.sh

to your openvpn.conf.
Eventually delete other "route-pull" commands.

Up script:

  
#!/bin/sh
ip rule add from 192.168.1.128/25 priority 10 table vpn
ip route add 192.168.1.128/25 dev tun1 table vpn
ip route add default via $ifconfig_remote dev tun1 table vpn
ip route flush cache

Down script:

  
#!/bin/sh
rm /etc/openvpn/cg/up
touch /etc/openvpn/cg/down
ip rule del from 192.168.1.128/25

When the OpenVPN tunnel comes up, the up-script is executed and traffic from 192.168.1.128-255 will be routed through the VPN.
When the tunnel goes down, this route will be deleted.

Hope, it helps.

you can use mwan3

@riodoro How did you setup cyberghost in openwrt as a client? I am struggling with this problem for days.

(Last edited by alewei on 28 May 2016, 16:22)

remlei wrote:

you can use mwan3

Thanks, I'll give it a try.

alewei wrote:

@riodoro How did you setup cyberghost in openwrt as a client? I am struggling with this problem for days.

Still actual?

The discussion might have continued from here.