REQ: Dual VPN client configurations (2 VPN tunnels)

Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware
Goto page 1, 2, 3  Next
Author Message
Brianwuz
DD-WRT User


Joined: 10 Feb 2010
Posts: 104

PostPosted: Thu Jan 25, 2018 10:33    Post subject: REQ: Dual VPN client configurations (2 VPN tunnels) Reply with quote
Router Model:Netgear R8000
Firmware Version: DD-WRT v3.0-r34320M kongac (01/03/1Cool
Kernel Version:Linux 4.4.109-rc1 #482 SMP Wed Jan 3 15:42:11 CET 2018 armv7l

Requesting the addition of a second VPN client configuration page like Tomato has. I have done a lot of searching and tried creating scripts that will bring up 2 tunnels and selectively route ips through ISP, Tun0 and TUN1 but without success.

Brian
Sponsor
Brianwuz
DD-WRT User


Joined: 10 Feb 2010
Posts: 104

PostPosted: Fri Jan 26, 2018 21:21    Post subject: Reply with quote
eibgrad, Thanks for you insight in to tomato's dual vpn setup. I have been working on scripts to create the two tunnels and will report back here with any successes for anyone else interested. Perhaps if we get a good script that is solid and works, providing ip based routing to the 3 tunnels (ISP, Tun0 and Tun1) then eventually it can be added to the GUI.

Brian
slice1900
DD-WRT User


Joined: 18 Feb 2013
Posts: 99

PostPosted: Fri Jan 26, 2018 23:44    Post subject: Reply with quote
I'm guessing this is probably a pretty niche requirement, so it isn't likely to get added in the GUI. But if they were going to do that, just adding the option for a second VPN would be the wrong approach.

You'd want to make it generic similar to stuff like bridges, VAPs etc. are generic and have an "add" button to add as many VPNs as you like.

IMHO it doesn't really make sense to add stuff like this to the GUI that are more of a power user thing, because the power users can figure out how to do with it with a script. There are a lot of things that would (hopefully) be higher on their list. Like hey, how about traffic/bandwidth stats per IP/MAC, or a way to dump the traffic of a specific connection to a log file for troubleshooting...
Brianwuz
DD-WRT User


Joined: 10 Feb 2010
Posts: 104

PostPosted: Sat Jan 27, 2018 9:00    Post subject: Reply with quote
slice1900 wrote:


IMHO it doesn't really make sense to add stuff like this to the GUI that are more of a power user thing, because the power users can figure out how to do with it with a script. There are a lot of things that would (hopefully) be higher on their list. Like hey, how about traffic/bandwidth stats per IP/MAC, or a way to dump the traffic of a specific connection to a log file for troubleshooting...


Brainslayers Special edition that he sells in the store has QOS per IP. Not sure what else extra it has as I haven't looked at it in a while. I did pay for it, but it never supported the routers I had so I couldn't ever use it.

Brian
maybeonly
DD-WRT Novice


Joined: 15 Mar 2007
Posts: 46

PostPosted: Sun Jan 28, 2018 5:41    Post subject: Reply with quote
Two or more tunnels can work fine, if separated routing tables (by 'ip route' commands) and routing rules (by 'ip rule' commands) are available.
In my option, as this function is not a common requirement, and it is possible through command lines, it is OK without a GUI.
Of course, network namespace will work better and we can do more with it. If developers can compile ip netns into the kernel, it will be great.
Brianwuz
DD-WRT User


Joined: 10 Feb 2010
Posts: 104

PostPosted: Sun Jan 28, 2018 8:58    Post subject: Reply with quote
Update 1

I copied the files that the gui creates from /tmp/openvpncl to /jffs/openvpncl. I can disable the gui and run the scripts and the tunnel comes up and works. There are routes that are pushed from the server in to the client. I need to run openvpn with the option --route-noexec. and instead of it applying the routes, it will put them in the route-up script where I can see all that it does and modify it.

Brian
janikeu
DD-WRT Novice


Joined: 01 Apr 2017
Posts: 1

PostPosted: Sun Jan 28, 2018 14:56    Post subject: Reply with quote
Hi,

Here is a part of my startup script to create a second VPN server (off course you have to customize it for your config), but I think it may help you

#OpenVPNsrv2 config
echo `date +'%F %T'` " " "Startup script openvpnsrv2 setup started..." >> /var/log/startup
cd /tmp
ln -s /usr/sbin/openvpn /tmp/openvpnsrv2

#setup router-router interfaces
openvpn --mktun --dev tap3
brctl addif br3 tap3 #add tap3 to the bridge (br3)
#brctl addif br14 tap3 #add tap3 to the bridge (br14)
#brctl addif br15 tap3 #add tap3 to the bridge (br15)
ifconfig tap3 0.0.0.0 promisc up

# Config
echo "
dh /tmp/openvpn/dh.pem
ca /tmp/openvpn/ca.crt
cert /tmp/openvpn/cert.pem
key /tmp/openvpn/key.pem
keepalive 10 120
verb 3
mute 3
syslog
writepid /var/run/openvpndsrv2.pid
management 127.0.0.1 12
management-log-cache 100
topology subnet
script-security 2
port 1303
proto udp4
cipher aes-256-cbc
auth sha512
client-connect /tmp/openvpn/clcon.sh
client-disconnect /tmp/openvpn/cldiscon.sh
client-config-dir /tmp/openvpn/ccd
comp-lzo adaptive
tls-server
ifconfig-pool-persist /tmp/openvpn/ip-pool-srv2 86400
client-to-client
fast-io
tun-mtu 1500
mtu-disc yes
server-bridge 192.168.103.1 255.255.255.0 192.168.103.60 192.168.103.64
#server-bridge 192.168.114.1 255.255.255.0 192.168.114.60 192.168.114.64
#server-bridge 192.168.115.1 255.255.255.0 192.168.115.60 192.168.115.64
dev tap3
#push "route 192.168.103.0 255.255.255.0"
" > /tmp/openvpn/openvpn-srv2.conf

#start opnvpnsrv2
/tmp/openvpnsrv2 --config /tmp/openvpn/openvpn-srv2.conf --route-up /tmp/openvpn/route-up.sh --route-pre-down /tmp/openvpn/route-down.sh --daemon
sleep 1
echo `date +'%F %T'` " " "Startup script openvpnsrv2 setup ended." >> /var/log/startup
Brianwuz
DD-WRT User


Joined: 10 Feb 2010
Posts: 104

PostPosted: Tue Jan 30, 2018 1:13    Post subject: Reply with quote
Janikeu,
I will examine your methods, but I am trying to get a second tun not a tap and some of the options in the .conf file are only for tap devices.
Brian
quarkysg
DD-WRT User


Joined: 03 May 2015
Posts: 323

PostPosted: Tue Jan 30, 2018 9:00    Post subject: Reply with quote
My DIR-880L running my own dd-wrt build connects to 3 VPN servers with the VPN clients scripts that I write. The GUI is too cumbersome for me to use effectively and only limited to 1 client, so I wrote my own scripts to startup and connects to all 3 sites' OpenVPN server. This allows me to manage the remote routers.

So it is perfectly achievable using dd-wrt builds. Your router just need to have enough juice to run so many processes.
Brianwuz
DD-WRT User


Joined: 10 Feb 2010
Posts: 104

PostPosted: Tue Jan 30, 2018 9:48    Post subject: Reply with quote
quarkysg wrote:
My DIR-880L running my own dd-wrt build connects to 3 VPN servers with the VPN clients scripts that I write. The GUI is too cumbersome for me to use effectively and only limited to 1 client, so I wrote my own scripts to startup and connects to all 3 sites' OpenVPN server. This allows me to manage the remote routers.

So it is perfectly achievable using dd-wrt builds. Your router just need to have enough juice to run so many processes.


Any chance you could share these scripts Smile

Brian
ludacrisvp
DD-WRT User


Joined: 21 Feb 2015
Posts: 102

PostPosted: Tue Jan 30, 2018 23:26    Post subject: Reply with quote
I too attempted to get a second TUN interface going for a second VPN connection.
As openVPN is limited to 1 thread and I have a dual core router I was wanting to get 2 running and have some load balancing and some VPN redundancy. I get that one machine won't be able to take advantage of both links for a single connection, however in some scenarios it could use both pipes and other machines would be able to use the extra bandwidth.

I was able to get multiple TUNs up / active and connected to the VPN provider at the same time but i could never get traffic to route properly. meaning that I could send traffic out both individually but nothing would come back on one of the links.

_________________
Routers:
WXR-1900DHP - Active (main) - v3.0-r36070M kongac (05/31/18 )
WZR-N600DHP - Wired AP - v3.0-r33679 BS (11/04/17)
WNDR-3400 - retired to its box for several years
ludacrisvp
DD-WRT User


Joined: 21 Feb 2015
Posts: 102

PostPosted: Tue Jan 30, 2018 23:38    Post subject: Reply with quote
Note this is pulled from a startup script i have ... some sections removed for this post.
Also, the VPN sections are commented out right now.

Code:

# cat /jffs/startup-script.sh
#!/bin/sh

logger -t custom-script 'Starting script run'
logger -t custom-script 'Unloading SFE that does not work with PBR'
/sbin/rmmod /lib/modules/4.4.95/shortcut-fe.ko
logger -t custom-script 'Loading PBR enabled custom SFE'
/sbin/insmod /jffs/shortcut-fe-32622+.ko
echo 4 > /sys/fast_classifier/offload_at_pkts

##### Add aliases
echo "alias ll='ls -plah --full-time --color=always'" >> /tmp/root/.profile
echo "alias ls='ls -pa --color=always'" >> /tmp/root/.profile
echo "alias ps='ps lT'" >> /tmp/root/.profile
echo "alias vpn='ps lT|grep vpn|grep -v grep; tail /tmp/mnt/sda1/vpn-tun*'" >> /tmp/root/.profile
echo "alias nano='vi'" >> /tmp/root/.profile


##################
# inactive section
##################
#logger -t custom-script 'Starting OpenVPN tun2'
#mknod /dev/tun2 c 10 200
#mknod /dev/net/tun2 c 10 200
#openvpn --config /jffs/openvpn/vpn2/openvpn-tun2.conf --route-up /jffs/openvpn/vpn2/route-up.sh --route-pre-down /jffs/openvpn/vpn2/route-down.sh --daemon
#sleep 1
#logger -t custom-script 'Starting OpenVPN tun3'
#mknod /dev/tun3 c 10 200
#mknod /dev/net/tun3 c 10 200
#openvpn --config /jffs/openvpn/vpn3/openvpn-tun3.conf --route-up /jffs/openvpn/vpn3/route-up.sh --route-pre-down /jffs/openvpn/vpn3/route-down.sh --daemon
##################
##################

logger -t custom-script 'Starting OpenVPN Bypass PBR'
NO_VPN_LST=`nvram get no_vpn_lst`
[ -z "$NO_VPN_LST" ] && exit 0
WAN_GWAY="0.0.0.0"
while [ $WAN_GWAY == "0.0.0.0" ]; do
sleep 1
WAN_GWAY=`nvram get wan_gateway`
done
ip route add default via $WAN_GWAY table 10 2>>/tmp/mnt/sda1/messages
for ipa in $NO_VPN_LST; do
ip rule add from $ipa table 10 2>>/tmp/mnt/sda1/messages
done

ip route flush cache 2>>/tmp/mnt/sda1/messages

logger -t custom-script 'Script completed'
exit 0


Example of tun2.conf I had been using TCP but really UDP should be used as if you think about it encapsulating TCP inside of TCP is a lot of overhead and can create some extreme latency if any of the TCP throttling features come in to play. Ultimately using UDP and having packet loss will still be handled correctly by your TCP packets that are buried in the UDP packets.

You need to set the management ports to different ports else it will fail.
You need to set different PID files too.
The OpenVPN settings shown may not be optimal.

Code:
# cat /jffs/openvpn/vpn2/openvpn-tun2.conf
ca /jffs/openvpn/vpn2/ca.crt
management 127.0.0.1 17
management-log-cache 100
verb 3
mute 3
syslog
writepid /var/run/openvpncl-tun2.pid
client
resolv-retry infinite
nobind
persist-key
persist-tun
script-security 2
dev tun2
proto tcp4-client
cipher aes-256-cbc
auth sha512
auth-user-pass /jffs/openvpn/vpn2/credentials
remote 102.11.39.41 443
comp-lzo yes
tun-mtu 1500
mtu-disc yes
tls-auth /jffs/openvpn/vpn2/ta.key 1
persist-key
tls-client
remote-cert-tls server
tun-mtu-extra 32
mssfix 1450
keepalive 5 30
ping-timer-rem
reneg-sec 0
resolv-retry infinite
remote-cert-tls server
remote-random
nobind
sndbuf 524288
rcvbuf 524288
mute 20
verb 3
log-append /tmp/mnt/sda1/vpn-tun2.log
dhcp-option DNS 10.10.10.1
dhcp-option DNS 8.8.4.4
dhcp-option DNS 4.2.2.2

_________________
Routers:
WXR-1900DHP - Active (main) - v3.0-r36070M kongac (05/31/18 )
WZR-N600DHP - Wired AP - v3.0-r33679 BS (11/04/17)
WNDR-3400 - retired to its box for several years
quarkysg
DD-WRT User


Joined: 03 May 2015
Posts: 323

PostPosted: Wed Jan 31, 2018 14:50    Post subject: Reply with quote
Brianwuz wrote:

Any chance you could share these scripts Smile

Brian


Here you go:

The following shell script accepts parameters and starts the OpenVPN client:

Code:
#!/bin/sh

if [ $# -ne 3 ]
then
  echo "Usage: $0 <dev> <client name> <client config>"
  exit 1
fi

TUN=$1
OVPNCL=$2
OVPNCLDIR=/tmp
OVPNCLCFG=$3

echo ------------------------------------------
echo [${OVPNCL}] starting up ...
echo
if [ ! -f ${OVPNCLDIR}/${OVPNCL} ]
then
  ln -s /usr/sbin/openvpn ${OVPNCLDIR}/${OVPNCL}
fi

if [ `ps | grep "./${OVPNCL}" | grep -v grep | wc -l` -gt 0 ]
then
  echo [${OVPNCL}] already running!
else
  cd ${OVPNCLDIR}

  echo Starting OpenVPN Client [${OVPNCL}] ...
  ./${OVPNCL} --cd ${OVPNCLDIR} --config ${OVPNCLCFG} --daemon
  sleep 5
  if [ `ps | grep "./${OVPNCL}" | grep -v grep | wc -l` -gt 0 ]
  then
    echo Done.
  else
    echo Unable to start OpenVPN Client [${OVPNCL}]!
  fi
fi

echo ------------------------------------------
echo


The following is the OpenVPN config for the client:

Code:
client
dev <tun dev>
mssfix 1400
nobind
proto udp
remote <VPN server> <port>
resolv-retry infinite
nobind
persist-key
ncp-ciphers AES-128-GCM:AES-256-GCM:AES-128-CBC:AES-256-CBC
verb 3
status-version 2                                 
status <status file name>
syslog
fast-io
writepid /var/run/<VPN client name>.pid
auth-nocache
#
ca <path to CA cert>
cert <path to client cert>
key <path to client private key>
remote-cert-tls server
verify-x509-name <server cert CN name> name
#
script-security 2
route-delay 5
route-up "<path to route action script> up"
route-pre-down "<path to route action script> pre-down"
#
ping 60
ping-restart 120


Replace the values within <> according to your environment.

Finally, the below is the route action script I used:

Code:
#!/bin/sh

ACTION=$1
DEV=$dev
VPN_GW=$route_vpn_gateway

case $ACTION in
up)
  # Add firewall rules
  /usr/sbin/iptables -D INPUT -i $DEV -j ACCEPT 
  /usr/sbin/iptables -D FORWARD -i $DEV -j ACCEPT
  /usr/sbin/iptables -D FORWARD -o $DEV -j ACCEPT 
  /usr/sbin/iptables -I INPUT 2 -i $DEV -j ACCEPT 
  /usr/sbin/iptables -I FORWARD 2 -i $DEV -j ACCEPT
  /usr/sbin/iptables -I FORWARD 2 -o $DEV -j ACCEPT
  ;;

pre-down)
  /usr/sbin/iptables -D INPUT -i $DEV -j ACCEPT   
  /usr/sbin/iptables -D FORWARD -i $DEV -j ACCEPT
  /usr/sbin/iptables -D FORWARD -o $DEV -j ACCEPT
  ;;

esac

exit 0


That should do it, I think, if I didn't miss out anything.

Feel free to customise for your own needs.

HTH.
Brianwuz
DD-WRT User


Joined: 10 Feb 2010
Posts: 104

PostPosted: Wed Jan 31, 2018 21:10    Post subject: Reply with quote
quarkysg,
Thank you for your scripts. They only seem to expand on the openvon.conf, route-up.sh and route-down.sh files that dd-wrt creates in /tmp/openvpncl. They do not address the main issue which is routing. Since you do not have a --no-pull or --route-noexec, then you are accepting routes pushed from the vpn server. This will delete the default gateway and route all traffic through the newly created tun. When you run the script again does the 2nd pushed route clobber the first and all data goes out the 2nd created tunnel or does the second tunnel not work. Seems that you would need to do a no pull and create selective routing to use more than one tunnel. All the firewall rules do is allow packets through the tunnel. They do not specify what packets or from what addresses.
I was asking in #openvpn on irc and was told I could get the pushed routes by setting verb 4 and logging. I am in the process of examining the log now. I believe ,for 2 tunnels and IPS routes that I need to set 3 blocks of ip's and route each block to ISP, TUN0, TUN1. Then I just assign pc to an ip in the right block to use the appropriate path.

Brian
quarkysg
DD-WRT User


Joined: 03 May 2015
Posts: 323

PostPosted: Wed Jan 31, 2018 22:03    Post subject: Reply with quote
Brianwuz wrote:
quarkysg,
Thank you for your scripts. They only seem to expand on the openvon.conf, route-up.sh and route-down.sh files that dd-wrt creates in /tmp/openvpncl. They do not address the main issue which is routing. Since you do not have a --no-pull or --route-noexec, then you are accepting routes pushed from the vpn server. This will delete the default gateway and route all traffic through the newly created tun. When you run the script again does the 2nd pushed route clobber the first and all data goes out the 2nd created tunnel or does the second tunnel not work. Seems that you would need to do a no pull and create selective routing to use more than one tunnel. All the firewall rules do is allow packets through the tunnel. They do not specify what packets or from what addresses.
I was asking in #openvpn on irc and was told I could get the pushed routes by setting verb 4 and logging. I am in the process of examining the log now. I believe ,for 2 tunnels and IPS routes that I need to set 3 blocks of ip's and route each block to ISP, TUN0, TUN1. Then I just assign pc to an ip in the right block to use the appropriate path.

Brian


I basically control all 4 routers at all 4 sites. The 3 sites’ VPN servers does not push default routes for clients so I do not need to worry about specifying routing rules in OpenVPN configs. I handle routing according to my needs using routing scripts, including PBR.

Do refer to the OpenVPN documentation for options you can configure. The latest version of dd-wrt include OpenVPN 2.4 so refer to that version. You’ll also need to understand the configuration that your VPN provider is pushing over so do check with them.

As dd-wrt is basically a Linux server, whatever networking stuff that applies to most Linux distro will work for dd-wrt routers as long as the user land program is available.
Goto page 1, 2, 3  Next Display posts from previous:    Page 1 of 3
Post new topic   Reply to topic    DD-WRT Forum Index -> Broadcom SoC based Hardware All times are GMT

Navigation

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum