I think I got it!
https://community.openvpn.net/openvpn/wiki/RoutedLans
trick is here:
OpenVPN Server side (192.168.0.0/24)
VPN Details: Advanced settings
Manage Client-Specific Options Yes
Allow Client <-> Client Yes
Allow only specified clients No
Custom Configuration
Code:route 192.168.1.0 255.255.255.0 push "route 192.168.1.0 255.255.255.0"
create on OpenVPN SERVER side (192.168.0.0/24):
/jffs/configs/openvpn/ccd1/
file named "client" - this should be common name, if you have changed it, you should name it accordingly
and put this code inside
Code:iroute 192.168.1.0 255.255.255.0
reboot OpenVPN server, reboot OpenVPN client
*change 192.168.1.0 address to your CLIENT LAN subnet, it could be differrent
*change 192.168.0.0 address to your SERVER LAN subnet, it could be differrent
now in OpenVPN status (server side) you should see this
Routes
Virtual Address Common Name Real Address Last Ref
10.8.0.6 client Sun May 31 02:08:38 2015
192.168.1.0/24 client Sun May 31 02:05:23 2015
from Server side (Asus router), I can ping Client LAN computers
@Merlin - what do you think about including OpenVPN site-to-site feature in next firmware release, at least as experimental feature? It should be dead simple to create one script
After further deliberation I believe the ASUSWRT outputs every .ovpn file as client and only allows 1 client? Is there a way to generate a second .ovpn with a different client so the second file /jffs/configs/openvpn/ccd1/client2 works? It seems it's not working nor connecting as client2 isn't an authorized client. Its all tied to 1 client.
I tried adding the 2nd iroute to the client file and renamed client2 back to client in the ovpn file. Now my Site C can connect to the server however from the Server and from Site B it can't see Site C.
Any thoughts?
To keep things simple, force the two clients to each use a separate Username/password combination to logon to the server.
This means both clients will use the same client.ovpn file, but the /jffs/openvpn/ccd1/client file cannot be used for specific client customisation.
Instead you will need to use a script such as:
https://www.snbforums.com/threads/o...e-to-site-connection.24268/page-4#post-306591"
which creates the virtual 'ccd1/client' file dynamically for each 'Username' as it connects to add the appropriate custom configuration such as the desired 'iroute' command.
NOTE: If you don't want to force the clients to authenticate then maybe if the clients have static I/P address (unlikely!) then the script should use the '$trusted_ip' rather than '$Username'
However, if you wish to create custom client files such as "SiteA.ovpn" and "SiteB.ovpn" (in order to use '/ccd1/SiteA' and '/ccd1/SiteB' file) then you need to follow
https://github.com/OpenVPN/easy-rsa/blob/v3.0.0-rc1/doc/EasyRSA-Readme.md"
EasyRSA can be installed on the router or Windows PC etc.
NOTE: If installing EasyRSA 3 on the router then I believe it also requires Entware utility 'mktemp'?
install Merlin's to run the script you and Merlin provide
OpenVPN scripts are allowed as a standard feature of the OpenVPN installation!
https://openvpn.net/index.php/open-source/documentation/manuals.html
I suggest you first try and run the client-connect script under stock ASUSWRT.
And what does it mean -script security 2 or higher must be enabled? Is that Server side or client side or both? And how to enable it?
# Customise clients - assign I/P address; share remote subnet etc:
#client-connect /jffs/scripts/VPNClientConnect.sh
# Automatically generated configuration
daemon
topology subnet
server 10.188.0.0 255.255.255.0
proto udp
multihome
port 1194
dev tun21
ncp-ciphers AES-128-GCM:AES-256-GCM:AES-128-CBC:AES-256-CBC
cipher AES-128-CBC
compress lz4
keepalive 15 60
verb 3
push "route 10.88.8.0 255.255.255.0 vpn_gateway 500"
client-config-dir ccd
client-to-client
duplicate-cn
push "dhcp-option DNS 10.88.8.1"
tls-crypt static.key
plugin /usr/lib/openvpn-plugin-auth-pam.so openvpn
ca ca.crt
dh dh.pem
cert server.crt
key server.key
script-security 2
up updown.sh
down updown.sh
status-version 2
status status 10
# Custom Configuration
# Customise clients - assign I/P address; share remote subnet etc:
#client-connect /jffs/scripts/VPNClientConnect.sh
script-security 2
# Customise clients - assign I/P address; share remote subnet etc:
client-connect /jffs/scripts/VPNClientConnect.sh
openvpn[8881]: xxx.xxx.xxx.xxx TLS: Username/Password authentication succeeded for username 'SGS5'
openvpn[8881]: xxx.xxx.xxx.xxx Control Channel: TLSv1.2, cipher TLSv1/SSLv3 ECDHE-RSA-AES256-GCM-SHA384, 1024 bit RSA
openvpn[8881]: xxx.xxx.xxx.xxx [client] Peer Connection Initiated with [AF_INET6]::ffff:xxx.xxx.xxx.xxx:36012
openvpn[8881]: client/xxx.xxx.xxx.xxx MULTI_sva: pool returned IPv4=10.188.0.3, IPv6=(Not enabled)
(VPNClientConnect.sh): 10114 VPN Client user 'SGS5' CCD configuration starting.... [/tmp/openvpn_cc_e070a460f17c33c64e0549f9d9313a2a.tmp]
(VPNClientConnect.sh): 10114 VPN Client user 'SGS5' CCD config: iroute 192.168.3.0 255.255.255.0
(VPNClientConnect.sh): 10114 VPN Client CCD configuration ended.
openvpn[8881]: client/xxx.xxx.xxx.xxx OPTIONS IMPORT: reading client specific options from: /tmp/openvpn_cc_e070a460f17c33c64e0549f9d9313a2a.tmp
openvpn[8881]: client/xxx.xxx.xxx.xxx MULTI: Learn: 10.188.0.3 -> client/xxx.xxx.xxx.xxx
openvpn[8881]: client/xxx.xxx.xxx.xxx MULTI: primary virtual IP for client/xxx.xxx.xxx.xxx: 10.188.0.3
openvpn[8881]: client/xxx.xxx.xxx.xxx MULTI: internal route 192.168.3.0/24 -> client/xxx.xxx.xxx.xxx
openvpn[8881]: client/xxx.xxx.xxx.xxx MULTI: Learn: 192.168.3.0/24 -> client/xxx.xxx.xxx.xxx
Server side - (P.S. you can always read the 2.4 OpenVPN manual from the URL I posted! )
If I have only the following directives in the Custom Config for Server1
Code:# Customise clients - assign I/P address; share remote subnet etc: #client-connect /jffs/scripts/VPNClientConnect.sh
then (when the OpenVPN Server1 instance successfully initialises) the following Server1 configuration file is generated and not only contains my two custom directives but also (seemingly by default?) the required 'script-security 2' directive.
Code:# Automatically generated configuration daemon topology subnet server 10.188.0.0 255.255.255.0 proto udp multihome port 1194 dev tun21 ncp-ciphers AES-128-GCM:AES-256-GCM:AES-128-CBC:AES-256-CBC cipher AES-128-CBC compress lz4 keepalive 15 60 verb 3 push "route 10.88.8.0 255.255.255.0 vpn_gateway 500" client-config-dir ccd client-to-client duplicate-cn push "dhcp-option DNS 10.88.8.1" tls-crypt static.key plugin /usr/lib/openvpn-plugin-auth-pam.so openvpn ca ca.crt dh dh.pem cert server.crt key server.key script-security 2 up updown.sh down updown.sh status-version 2 status status 10 # Custom Configuration # Customise clients - assign I/P address; share remote subnet etc: #client-connect /jffs/scripts/VPNClientConnect.sh
This is using the RMerlin firmware (as we are in the Asuswrt-Merlin firmware forum!!!)
EDIT: If the firmware does not have the 'Selective Routing Policy rules' option in the VPN Client GUI then you must explicitly specify the 'script-security 2' directive.
e.g. Try cut'n'paste the following into the Custom config and see if the Server initialises correctly and the script is invoked for a client connection:
Code:script-security 2 # Customise clients - assign I/P address; share remote subnet etc: client-connect /jffs/scripts/VPNClientConnect.sh
Just attempted a client connection to my Server1
Code:openvpn[8881]: xxx.xxx.xxx.xxx TLS: Username/Password authentication succeeded for username 'SGS5' openvpn[8881]: xxx.xxx.xxx.xxx Control Channel: TLSv1.2, cipher TLSv1/SSLv3 ECDHE-RSA-AES256-GCM-SHA384, 1024 bit RSA openvpn[8881]: xxx.xxx.xxx.xxx [client] Peer Connection Initiated with [AF_INET6]::ffff:xxx.xxx.xxx.xxx:36012 openvpn[8881]: client/xxx.xxx.xxx.xxx MULTI_sva: pool returned IPv4=10.188.0.3, IPv6=(Not enabled) (VPNClientConnect.sh): 10114 VPN Client user 'SGS5' CCD configuration starting.... [/tmp/openvpn_cc_e070a460f17c33c64e0549f9d9313a2a.tmp] (VPNClientConnect.sh): 10114 VPN Client user 'SGS5' CCD config: iroute 192.168.3.0 255.255.255.0 (VPNClientConnect.sh): 10114 VPN Client CCD configuration ended. openvpn[8881]: client/xxx.xxx.xxx.xxx OPTIONS IMPORT: reading client specific options from: /tmp/openvpn_cc_e070a460f17c33c64e0549f9d9313a2a.tmp openvpn[8881]: client/xxx.xxx.xxx.xxx MULTI: Learn: 10.188.0.3 -> client/xxx.xxx.xxx.xxx openvpn[8881]: client/xxx.xxx.xxx.xxx MULTI: primary virtual IP for client/xxx.xxx.xxx.xxx: 10.188.0.3 openvpn[8881]: client/xxx.xxx.xxx.xxx MULTI: internal route 192.168.3.0/24 -> client/xxx.xxx.xxx.xxx openvpn[8881]: client/xxx.xxx.xxx.xxx MULTI: Learn: 192.168.3.0/24 -> client/xxx.xxx.xxx.xxx
[COLOR=#000000]Mar 15 13:18:24 openvpn[3018]: XX.XX.XX.XX:XX TLS: Username/Password authentication succeeded for username 'client2'
Mar 15 13:18:24 openvpn[3018]: XX.XX.XX.XX:XX Control Channel: TLSv1.2, cipher TLSv1/SSLv3 ECDHE-RSA-AES256-GCM-SHA384, 1024 bit RSA
Mar 15 13:18:24 openvpn[3018]: XX.XX.XX.XX:XX [client] Peer Connection Initiated with [AF_INET6]::ffff:XX.XX.XX.XX:XX:38349
Mar 15 13:18:24 openvpn[3018]: client/XX.XX.XX.XX:XX MULTI_sva: pool returned IPv4=10.2.0.2, IPv6=(Not enabled)
Mar 15 13:18:24 openvpn[3018]: client/XX.XX.XX.XX:XX [/COLOR][COLOR=#ff0000]WARNING: Failed running command (--client-connect): could not execute external program[/COLOR]
[COLOR=#000000]Mar 15 13:18:25 openvpn[3018]: client/XX.XX.XX.XX:XX PUSH: Received control message: 'PUSH_REQUEST'
Mar 15 13:18:25 openvpn[3018]: client/XX.XX.XX.XX:XX Delayed exit in 5 seconds
Mar 15 13:18:25 openvpn[3018]: client/XX.XX.XX.XX:XX SENT CONTROL [client]: 'AUTH_FAILED' (status=1)
Mar 15 13:18:30 openvpn[3018]: client/XX.XX.XX.XX:XX SIGTERM[soft,delayed-exit] received, client-instance exiting
[/SPOILER][/QUOTE][/COLOR]
[COLOR=#ff0000][/COLOR]
In regards to the manual for 3.4 I did search it and there was nothing with "-script security 2" I couldn't find that anywhere.
Strange, when I browse the OpenVPN 3.4 [sic] manual (using the URL I posted) I find this...
View attachment 8748
Did you cut'n'paste the three lines exactly as I posted?
Post the '/etc/openvpn/server1/config.ovpn' file.
Also did you make the script file executable as per the wiki? https://github.com/RMerl/asuswrt-merlin/wiki/User-scripts
Steps taken:
1) Made sure to follow Merlins advice to enable the custom scripts in System and then to remember to set the permission properties chmod a+rx /jffs/scripts/*
# Custom Configuration
script-security 2
client-connect /jffs/scripts/VPNClientConnect.sh
route 192.168.3.0 255.255.255.0 vpn_gateway
route 192.168.4.0 255.255.255.0 vpn_gateway
push "route 192.168.3.0 255.255.255.0"
push "route 192.168.4.0 255.255.255.0"
cd /jffs/scripts/
l -lah ./VPNClientConnect.sh
./VPNClientConnect.sh
chmod a+rx /jffs/scripts/*
l -lah ./VPNClientConnect.sh
./VPNClientConnect.sh
dos2unix ./VPNClientConnect.sh
./VPNClientConnect.sh
cat ./VPNClientConnect.sh | head
EDIT: If '/jffs/scripts/openvpn-event' doesn't exist then you must explicitly specify the 'script-security 2' directive.
Using username "userx".
Authenticating with public key "rsa-key-20150809"
Passphrase for key "rsa-key-20150809":
ASUSWRT-Merlin RT-AC68U 380.65-2 Fri Mar 10 05:29:50 UTC 2017
userx@RT-AC68R-2DA8:/tmp/home/root# cd /jffs/scripts/
userx@RT-AC68R-2DA8:/jffs/scripts# l s -lah ./VPNClientConnect.sh
-rwxr-xr-x 1 userx root 1.9K Mar 15 16:23 ./VPNClientConnect.sh
userx@RT-AC68R-2DA8:/jffs/scripts# ./VPNClientConnect.sh
(VPNClientConnect.sh): 3366 VPN Client user '' CCD configuration starting.... []
(VPNClientConnect.sh): 3366 **WARNING VPN Client user '' not defined - dynamic CCD config skipped.
(VPNClientConnect.sh): 3366 VPN Client CCD configuration ended.
userx@RT-AC68R-2DA8:/jffs/scripts# chmod a+rx /jffs/scripts/*
userx@RT-AC68R-2DA8:/jffs/scripts# l s -lah ./VPNClientConnect.sh
-rwxr-xr-x 1 userx root 1.9K Mar 15 16:23 ./VPNClientConnect.sh
userx@RT-AC68R-2DA8:/jffs/scripts# ./VPNClientConnect.sh
(VPNClientConnect.sh): 3382 VPN Client user '' CCD configuration starting.... []
(VPNClientConnect.sh): 3382 **WARNING VPN Client user '' not defined - dynamic CCD config skipped.
(VPNClientConnect.sh): 3382 VPN Client CCD configuration ended.
userx@RT-AC68R-2DA8:/jffs/scripts# dos2unix ./VPNClientConnect.sh
userx@RT-AC68R-2DA8:/jffs/scripts# ./VPNClientConnect.sh
(VPNClientConnect.sh): 3398 VPN Client user '' CCD configuration starting.... []
(VPNClientConnect.sh): 3398 **WARNING VPN Client user '' not defined - dynamic CCD config skipped.
(VPNClientConnect.sh): 3398 VPN Client CCD configuration ended.
userx@RT-AC68R-2DA8:/jffs/scripts#
#!/bin/sh
#=============================================================================
#
# This VPN Server custom script will create a CCD/tmp_file based on 'User names' when they share the same 'Common name' e.g. 'client'
#
# i.e. CCD file '/jffs/configs/openvpn/ccd1/client' is inappropriate for multiple concurrent clients
#
# The remote subnets for each individual User (identified by login credentials) will be defined etc.
#
# e.g. VPN Server 192.168.5.0 will host two clients (each with its own LAN subnet) and all three will communicate with each other over the VPN tunnels
#
# Requires VPN Server directives:
#
# client-to-client
# duplicate-cn
# # Custom Configuration
# client-connect /jffs/scripts/VPNClientConnect.sh
#
logger -st "($(basename $0))" $$ "VPN Client user '"$username"' CCD configuration starting...." [$@]
# Configure the VPN Client CCD/file dynamically
STATUS="OK" # Let's be positive! ;-)
# Identify client
case "$username" in
"client1")
echo "iroute 192.168.3.0 255.255.255.0" >>$1
;;
"client2")
echo "iroute 192.168.4.0 255.255.255.0" >>$1
;;
*)
STATUS="FAIL"
;;
esac
if [ "$STATUS" == "OK" ];then
logger -st "($(basename $0))" $$ "VPN Client user '"$username"' CCD config:" `cat $1`
else
echo -e "\a"
logger -st "($(basename $0))" $$ "**WARNING VPN Client user '"$username"' not defined - dynamic CCD config skipped."
fi
#Send_email [file | "A_single_line_text_message_in_quotes_to_be_emailed" ] [email_method]
TEMPFILE="/tmp/VPNClientConnect"${username}".txt"
echo "Common Name: $common_name" >>$TEMPFILE
echo "Username: $username" >>$TEMPFILE
echo "I/P: $trusted_ip" >>$TEMPFILE
echo "PORT:$trusted_port" >>$TEMPFILE
echo "MTU: $tun_mtu" >>$TEMPFILE
#Send_email $TEMPFILE
logger -st "($(basename $0))" $$ "VPN Client CCD configuration ended."
exit 0
What is the /openvpn-event?
Below is the debug. **Note in the script the only changes were the client1 and client 2 names like you stated. and I did change the "l" to "ls" to run it.
Users choose the RMerlin firmware because of its extensive customisation via scripting - you can read about openvpn-event (see Usage->User scripts) and all the others (Usage->Customising config files etc.) here:
https://github.com/RMerl/asuswrt-merlin/wiki
So since openvpn-event is an optional RMerlin recognised custom script, if it exists then clearly for it to execute, the 'script-security 2' directive is obviously mandatory. - Doh!
The script appears to run correctly (several times) on the console - and I assume it has created the associated logfile in '/tmp' ?
So I can see no reason why the clients when they connect don't show the script executing.
If you temporarily remove the need for Username/password authentication,, can client1/2 connect with the script seen as running in Syslog?
@Martineau I figured it out. I happened to be browsing another Having trouble running custom scripts that had some issue that you also helped with.
My issue seemed to be the encoding. Even though I had created it prior with Notepad++ and copied it over via SCP it didn't recognize. What I did is delete the file and recreate it using the internal editor in WinSCP and save again.. chmod it to allow execute and boom retried and it worked fine.
I have all 3 sites working now thanks to you! You were a big help in guiding me and providing the scripts.
Thanks for the feedback! - I can now finally relax ....I was 200% sure that my script worked but I must admit I was starting to doubt my abilities
Agree with you AbOrigine, have tried to follow this but don't get it. Working just one way.Would anyone be willing to write a step-by-step guide to the whole process?
I guess it will benefit people who are not that much Linux/OpenVPN savvy (like for example - me).
Welcome To SNBForums
SNBForums is a community for anyone who wants to learn about or discuss the latest in wireless routers, network storage and the ins and outs of building and maintaining a small network.
If you'd like to post a question, simply register and have at it!
While you're at it, please check out SmallNetBuilder for product reviews and our famous Router Charts, Ranker and plenty more!