Hi,
in this guide i will show you how to set up a vpn-connection with a automatically location change and good settings for your ovpn-file so the connection is stable and your router can handle the 24 hours disconnect from some openvpn providers. Also your router will check every minute for a stable internet connection and reconnect it. If my version won’t work, try the scripts below in the next post!
[HowTo]
-
Download the ovpn-file from your provider and edit it with a texteditor
-
Compare it with my ovpn-file an add missing lines, but don’t change commands if your vpn provider use other settings for one command → Don’t change such commands!
Here is my file!
remote uk-lon2.privatevpn.com 1194 udp
remote [youradress] [port] [type] #add how many locations you like, above is a example
remote-random
nobind
dev tun
Options
tun-ipv6
remote-cert-tls server
client
comp-lzo
persist-key
persist-tun
verb 3
Router
reneg-sec 0
auth-nocache
connection retry -1
route-delay
keepalive 3 10
resolv-retry infinite
auth-retry interact
ping-restart 0
ping-timer-rem
pull-filter ignore “auth-token”
log /etc/openvpn/openvpn.log
Crypto
cipher AES-128-GCM
auth SHA256
auth-user-pass
Cert
-----BEGIN CERTIFICATE-----
[Here is your ca code in it]
-----END CERTIFICATE-----
-----BEGIN OpenVPN Static key V1-----
[Here is your key code in it]
-----END OpenVPN Static key V1-----
key-direction 1
-
Remote-Random will chose every time there is a restart select a new location from your remote servers. So add “remote ”. Add how many you like!
-
Import the Settings to your router like you see it here and start the vpn:
GL.iNet setup with NordVPN | NordVPN support -
Login in Luci and than go to: System->Software and search for nano and install it
-
Go into Terminal (Linux) and write:
ssh root@192.168.1.1
->hit enter and use your forris/luci passwort
- Write this and hit enter:
nano /usr/bin/vpn_reconnect
- Copy/Paste this script:
#!/bin/sh
# Check vpn-tunnel "tun0" and ping cz.nic if internet connection work
if [ "$(ping -I tun0 -q -c 1 -W 1 193.17.47.1 | grep '100% packet loss' )" != "" ]; then
logger -t VPN_Reconnect VPN-Tunnel "tun0" has got no internet connectionection -> restart it
/etc/init.d/openvpn stop
sleep 3
/etc/init.d/openvpn start
else
logger -t VPN_Reconnect VPN-Tunnel "tun0" is working with internet connection
fi
and then do Strg + o than Enter than Strg + x
Then:
chmod +x /usr/bin/vpn_reconnect
- To set up a cronjob, use this first in terminal:
crontab -e
- Write this code in it (Check every minute for vpn-connection)
*/1 * * * * /usr/bin/vpn_reconnect
- Optional: Add this code for manual restart (My Example: Restart of vpn everyday at 3:30am)
30 3 * * * /etc/init.d/openvpn stop ; /etc/init.d/openvpn start
- If you want you can add a second line to restart your router 1 time in the year
Or more often, do what you want!
* * 1 1 * sleep 70 && touch /etc/banner && reboot
- You can set your times by yourself, here you see the timetable:
* * * * * command to be executed
- - - - -
| | | | |
| | | | +----- day of week (0 - 6) (Sunday=0)
| | | +------- month (1 - 12)
| | +--------- day of month (1 - 31)
| +----------- hour (0 - 23)
+------------- min (0 - 59)
- A few other commands, which may or may not be necessary to ensure that cron was running:
/etc/init.d/cron start
/etc/init.d/cron enable
/etc/init.d/cron restart
-
You can actually interact with cron through the web panel as well and check if the settings are saved > System > Scheduled tasks and check if the script is working in the system log: Status->System Log
-
With “Remote-Random” at stop & start of openvpn your router will choose a random remote server from your ovpn-file like you can see here too: HowToOpenVPNClient
→ With this two tutorials now your connection should be stable all the time and with location change and router restart like you want it. If not, check the post below! Don’t forget to enable openvpn on router restart and only allow vpn internet access like in the other script!
Have fun