Hi guys,
I have two routers in different locations, ASUS RT-AC55U with original firmware, 192.168.2.1, which will be referred as
server and Asus RT-N10U with AdvancedTomato firmware, 192.168.3.1, which will be referred as
client.
client will be connected to
server permanently using OpenVPN. I think it would be very easy if both would be Tomato/DD-WRT/Merlin firmwares, but AC55U doesn't have neither Tomato, DD-WRT nor Merlin firmwares for it.
Here is manual how I got everything working for myself.
I needed to connect those two networks and
* use TUN protocol (because TAP is not iphone compatible)
* be able to have client - client connections (iphone on mobile network -> OpenVPN to
server -> connect to
clients router devices)
* have access to Samba share on
server from devices on
client router, and from other VPN clients(iphone)
Server (Asus fw):
OpenVPN server set up using Asus web interface:
1. General config: two users defined:
router(for Tomato VPN client connection) and
iphone.
2. Advanced settings: basically all default settings for TUN protocol(TUN, UDP, 1194, Auto Firewall, TLS authorization, User/Pass Auth. Only set to No, HMAC disable, VPN Subnet 10.8.0.0 with mask 255.255.255.0, poll 0, Push Lan to clients yes, direct clients to redirect Internet traffic no, respond to DNS Yes, Advertise DNS no, manage CLient-Specific Options yes, Allow Client <>CLient yes, Allow only specified clients no)
3. Allowed clients
must be empty (script will take care of that)
4. Custom configuration
Code:
script-security 2
# Assign static I/P addresses to clients (and optionally add ADVANCED CCD directives)
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"
Note here - 192.168.4.0 is definet and pushed for iphone client which I later might use for another router. Currently it doesn't mess my iphone connection so I left it like this.
5. Edit Martineau VPNClientConnect.sh script(from
https://www.snbforums.com/threads/o...e-to-site-connection.24268/page-4#post-306591). router and iphone usernames from step 1 are configured in script accordingly. router has network 192.168.3.0 which is main part that I need to provide working.
Code:
#!/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
"router")
echo "iroute 192.168.3.0 255.255.255.0" >>$1
;;
"iphone")
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
6. Now create /jffs/scripts/VPNClientConnect.sh script which mentioned in Custom configuration.
ssh to
server, using admin/pass from web admin.
Code:
mkdir /jffs/scripts
vi /jffs/scripts/VPNClientConnect.sh
#in this step paste script into file
#copy script from it's source,
#:set noautoindent
#i
#Shift+Insert, Esq
#:wq
#Enter
chmod +x /jffs/scripts/VPNClientConnect.sh
This seems to be all that is needed for
client to connect to
server, and iphone vpn client can connect to devices on
client router network which is connected through OpenVPN.
Samba share set up using Asus web interface.
Problem in the end is that iphone can connect through VPN-
server to Samba share, but
client routers clients cannot, because their IPs are 192.168.3.X (iphones IP apparently seems to be 10.8.0.X for Samba server)
Next I used work of
https://github.com/dnlongen/ASUSWRT_Samba_Fixer
ssh to
server, and
Code:
#create copy of original smb.conf
cp /etc/smb.conf /jffs/smb.conf
vi /jffs/smb.conf
#now, find "hosts allow = 127.0.0.1 192.168.2.1/255.255.255.0 10.8.0.0/255.255.255.0" line and add " 192.168.3.1/255.255.255.0" in the end of it
#samba connection for me didn't work until I changed this line in both [global] and [ipc$] sections.
#I created fixsamba file as fix_things.sh in order to add there additional things later
vi /jffs/scripts/fix_things.sh
#put there https://github.com/dnlongen/ASUSWRT_Samba_Fixer/blob/master/fixsamba script same way as it was done in step 6 of VPN server configuration.
#make this script to run on USBmount event, which as I understood only way to execute scripts as close to router startup as possible.
chmod 755 /jffs/scripts/fix_things.sh
nvram set script_usbmount="/jffs/scripts/fix_things.sh"
nvram commit
Now, clients of
client router can connect to samba share on
server router.
Client (Tomato):
Set up as OpenVPN Client (Start with WAN checked, Interface Type TUN, Protocol UDP, server address and port: those of your server, Firewall automatic, authorization TLS, Username/Password Authentication checked, Username: router, Password: whateverpasswordissetforrouter, Username Authen. Only unchecked, Extra HMAC authorization (tls-auth) Disabled, Create NAT on tunnel unchecked.).
In advanced (Redirect Internet traffic unchecked, Ignore Redirect Gateway (route-nopull) unchecked, Accept DNS configuration Relaxed)
Keys - those keys that are saved in .ovpn gotten from
server.
That's basically it.
client router connected to
server router through OpenVPN. Devices on
server router can connect to clients on
client router and vice versa. Another VPN client (iphone) can connect to
client router clients or
server router clients. Devices from both
server or
client routers have access to samba share on server router, as well as iphone vpn client.