NETGEAR is aware of a growing number of phone and online scams. To learn how to stay safe click here.

Forum Discussion

wizhack's avatar
wizhack
Aspirant
Aug 28, 2016

How to connect automaticly as vpn client in readey nas 104

Hello i'm using a vpn server and i would like to know how to connect my ready nas automaticly when the nas boot, i'm using hide my a** as vpn service and using the hma script too.

For the moment i have to connect in ssh and ./hma-bla-bla.sh -d (-d for daemonize).

here is the script i'm using for the moment, i had to remove all "sudo" cmd because im connecting as root to my nas,i have to login and select the server manually.

 

Spoiler
#!/bin/bash

trap ctrl_c INT

function ctrl_c() {
echo
echo "Exiting script..."
echo
stty echo
exit 0
}

function showhelp()
{
echo "- Available switches:"
echo "./hma-openvpn.sh -h = Show help"
echo "./hma-openvpn.sh -d = Daemonize OpenVPN"
echo
echo "- Please ensure to have this packages installed:"
echo "  curl, openvpn, wget, dialog"
echo "  e.g.: yum install curl openvpn wget dialog"
echo "    or: apt-get install curl openvpn wget dialog"
echo
}

while getopts "dh" parm
do
        case $parm in
        d)
                daemonize=1
                ;;
        ?)      echo
        echo "HMA-OpenVPN Script"
        echo "=================="
        echo
        showhelp
        exit 0
        ;;
        esac
done


showtitle() {
clear
green="\e[36;5;82m"
stdcol="\e[0m"
echo
echo -e "$green =============================="
echo " |     __  ____  ______    __ |"
echo " |    / / / /  |/  /   |  / / |"
echo " |   / /_/ / /|_/ / /| | / /  |"
echo " |  / __  / /  / / ___ |/_/   |"
echo " | /_/ /_/_/  /_/_/  |_(_)    |"
echo " |                            |"
echo " |     HMA! OpenVPN Script    |"
echo " =============================="
echo
echo "-> https://hidemyass.com/vpn"
echo -e "-> https://support.hidemyass.com$stdcol"
echo
}

showtitle
showhelp

sleep 3
echo "- Getting HMA! Pro VPN serverlist..."
sleep 1
wget -q http://hidemyass.com/vpn-config/l2tp/ -O /tmp/serverlist.txt

LINES=$(cat /tmp/serverlist.txt)

IFS=$'\n\t'
dialog --backtitle "HMA! OpenVPN Script" \
--title "Select a server" \
--menu "Select a server" 17 78 15 $LINES 2>/tmp/hma-server
unset IFS

sleep 1
hmaserver=`cat /tmp/hma-server`
clear

dialog --backtitle "HMA! OpenVPN Script" \
--title "Select protocol" \
--radiolist "Use OpenVPN-TCP (port 443) or OpenVPN-UDP (port 53)?" 10 40 3 UDP "" on TCP "" off 2>/tmp/hma-proto
sleep 1

showtitle
hmaproto=`cat /tmp/hma-proto | tr '[:upper:]' '[:lower:]'`
echo "- Getting .ovpn template..."
echo
sleep 1
wget -O /tmp/hma-template.ovpn http://hmastuff.com/hma-template.ovpn

echo "proto $hmaproto" >> /tmp/hma-template.ovpn

if [ "$hmaproto" == "udp" ]; then
echo "remote $hmaserver 53" >> /tmp/hma-template.ovpn
hmaport=53
fi
if [ "$hmaproto" == "tcp" ]; then
echo "remote $hmaserver 443" >> /tmp/hma-template.ovpn
hmaport=443
fi

showtitle

function checkip()
{
ip=""
attempt=0
while [ "$ip" = "" ]; do
        attempt=$(($attempt+1))
        ip=`curl http://geoip.hidemyass.com/ip/ 2>/dev/null`
        if [ "$ip" != "" ]; then
                echo "- Your current IP is: $ip"
        fi
        if [ $attempt -gt 3 ]; then
                echo "- Failed to check current IP address."
                exit
        fi
done
}

checkip
sleep 1

echo
echo "- Starting OpenVPN connection to: $hmaserver : $hmaport ($hmaproto) ..."
sleep 1
echo

if [ "$daemonize" == "1" ]; then
openvpn --daemon --script-security 3 --config /tmp/hma-template.ovpn
echo
echo "Waiting 10 seconds for doing IP-check..."
sleep 10
echo
checkip
echo
echo "Disconnect via: sudo killall openvpn"
echo
else
openvpn --script-security 3 --config /tmp/hma-template.ovpn
fi

tput sgr0
exit 0

thanks for the help

basicly i would like the script try to connect when i have internet connection, when the power get back in the house for example, wait 1 minute after boot or try to ping google or any website before trying to connect.

2 Replies

Replies have been turned off for this discussion
  • JennC's avatar
    JennC
    NETGEAR Employee Retired

    Hello wizhack,

     

    This was posted in August, it appears that something has been changed and done from the backend. I guess it is best to wait for other community members to share their thoughts and experience.

     

    Regards,

  • JennC's avatar
    JennC
    NETGEAR Employee Retired

    Hello wizhack,

     

    Have you received any feedback from any of the members?

     

    Regards,

NETGEAR Academy

Boost your skills with the Netgear Academy - Get trained, certified and stay ahead with the latest Netgear technology! 

Join Us!

ProSupport for Business

Comprehensive support plans for maximum network uptime and business peace of mind.

 

Learn More