bluechris
Occasional Visitor
Hi guys
I setup my router with Dual Wan in load balance and i have one openvpn client.
All is working fine with one problem only (if i you can say that) and this is that i cannot control somehow from which wan the opevnvpn will connect and i need the openvpn to be connected with wan1.
I need some help here because i cannot find a way to do this.
thx in advance
chris
EDIT:
1st Solution if you know the wan ip that you want your VPN to go out.
you create a file in /jffs/scripts with name openvpnclient1.postconf
In this file you put this inside
where xxx.xxx.xxx.xxx is your wan ip.
You Reboot the router and your openvpn client1 connects from the specific wan and you can see that in syslog.
2nd Solution to get the wan ip dynamically from @Martineau
You do the same file as in 1st solution but inside you put this
This script is suppose to dynamically get the wan ip address and alters the openvpn config and with that you choose from which wan you want your openvpn client to go out. See the script and you will understand what it does. Unfortunatelly in my case it gives back not the wan ip but the Gateway ip and needs some fixing but you can try it for sure.
If anyone get positive response of the script and is working for him i will take out the 1st solution.
thx everyone for the help and especially @Martineau for his time and effort.
I setup my router with Dual Wan in load balance and i have one openvpn client.
All is working fine with one problem only (if i you can say that) and this is that i cannot control somehow from which wan the opevnvpn will connect and i need the openvpn to be connected with wan1.
I need some help here because i cannot find a way to do this.
thx in advance
chris
EDIT:
1st Solution if you know the wan ip that you want your VPN to go out.
you create a file in /jffs/scripts with name openvpnclient1.postconf
In this file you put this inside
Code:
#!/bin/sh
CONFIG=$1
source /usr/sbin/helper.sh
pc_replace "nobind" "local xxx.xxx.xxx.xxx" $CONFIG
where xxx.xxx.xxx.xxx is your wan ip.
You Reboot the router and your openvpn client1 connects from the specific wan and you can see that in syslog.
2nd Solution to get the wan ip dynamically from @Martineau
You do the same file as in 1st solution but inside you put this
Code:
#!/bin/sh
#
# Version 1.01
#
# This script allows you to specify which WAN interface is to be used for this VPN Client connection...
#
# e.g. WAN0 may be a Slow/Expensive/Data-capped 3/4G link but WAN1 may be a fast VDSL/Fibre link
#
# So in the VPN Client Custom Configuration dialog box enter
#
# local wan1
# or if you *REALLY* want to force the VPN tnnel via the EXPENSIVE 3/4G WAN...
# local wan0
#
# and the current ACTIVE BIND I/P address for the requested virtual WAN interface will be extracted from the DUAL-WAN tables
#
#
# NOTE: If DUAL-WAN is not configured, then if alias 'br0:VPN' exists:
#
# i.e. 'ifconfig br0:VPN xxx.xxx.xxx.xxx up' was created in '/jffs/scripts/init-start'
#
# then xxx.xxx.xxx.xxx will be EXPLICITY used - just to prove this script works!! ;-)
# i.e. it will ignore the actual WANx directive specified
#
# 'local wan1' -> 'local br0:VPN'
CONFIG=$1
source /usr/sbin/helper.sh
logger -st "($(basename $0))" $$ "Started....." [$@]
# Check if DUAL-WAN interfaces exist
if [ "$(nvram get wans_dualwan)" == "wan none" ];then
VPN_IF="br0:VPN" # For SINGLE-WAN default 'WAN0', use the alias 'br0:VPN' if it exists
BIND_IP=$(ifconfig $VPN_IF | grep 'inet addr'|cut -d':' -f2 | awk '{print $1}') # For testing! ;-)
else # DUAL-WAN assumed
VPN_IF=$(grep -iE "^local" $CONFIG | cut -d" " -f2) # Get virtual 'WAN0/1' from custom config GUI
VLAN_ID=$(ip route show table $VPN_IF | grep "default" | awk '{print $5}') # Extract the real 'vlanX' interface name referenced by WAN0/1
BIND_IP=$(ifconfig $VLAN_ID | grep 'inet addr'|cut -d':' -f2 | awk '{print $1}') # Get the I/P assigned to the 'vlanX' interface
fi
# Do we have a valid BIND address?
if [ -z "$BIND_IP" ] && [ "${VPN_IF:0:3}" == "wan" ];then
logger -st "($(basename $0))" $$ "***ERROR** VPN Client WAN BIND I/P address not found for virtual interface '"$VPN_IF"'"
echo -e "\a"
exit 99
fi
# Use the valid BIND address if we have one! -> 'local xxx.xxx.xxx.xxx'
if [ ! -z "$BIND_IP" ];then # If 'local' specified then update it
if [ "${VPN_IF:0:3}" == "wan" ];then # Still using the virtual interface names?
VPN_IF=$(ip route show table $VPN_IF | grep "default" | awk '{print $5}') # Cosmetic..replace virtual 'wan0/1' with say 'vlan2/3'
fi
logger -st "($(basename $0))" $$ "VPN Client will BIND to" $BIND_IP "via interface '"$VPN_IF"'"
#pc_delete "nobind" $CONFIG # Delete the conflicting 'nobind' option using the new 'helper' function to see if it works!
sed -i "s/^nobind.*$//" $CONFIG # Only Firmware >380.63+ includes 'pc_delete' :-(
sed -i "s/^local.*$/local $BIND_IP/" $CONFIG # Replace the virtual 'local wanX' to force the VPN Client to BIND to the desired WAN interface
# It would be nice if we could put a comment in the GUI? - Version 2 perhaps! ;-)
# e.g. nvram set vpn_client1_custom="<existing># Using BIND $BIND_IP via $VPN_IF"
else
logger -st "($(basename $0))" $$ "VPN Client allowed to BIND to any WAN interface ('"$VPN_IF"' not found!)"
sed -i "s/^local.*$//" $CONFIG # Just in case?????!!!!! ;-)
fi
logger -st "($(basename $0))" $$ "Complete."
exit 0
This script is suppose to dynamically get the wan ip address and alters the openvpn config and with that you choose from which wan you want your openvpn client to go out. See the script and you will understand what it does. Unfortunatelly in my case it gives back not the wan ip but the Gateway ip and needs some fixing but you can try it for sure.
If anyone get positive response of the script and is working for him i will take out the 1st solution.
thx everyone for the help and especially @Martineau for his time and effort.
Last edited: