Breadcrumbs

1. Introduction

Cette article décrit comment faire pour que le synology utilise le service No-IP:

pour cela il faut :

  • le script noip
  • ajouter dans la crontab l'appelle du script régulierement

 

2.Configuration

2.1 Script NOIP

#!/bin/sh
# This script gets the public IP address and update the no-ip.org host
# Useful only when the Synology has more than 1 IP address
# The update request to no-ip.org was inspired by Simple Bash No-IP Updater/0.4 from This email address is being protected from spambots. You need JavaScript enabled to view it.
#

UserName="**********"
PassWord=""*******
MyHost="**********.no-ip.org"
GatewayIP="192.168.x.x"

Server2GetIP="icanhazip.com"
NameServer="8.8.8.8"
UserAgent="Synology Public IP Update"
PublicIPfile="/tmp/MyPublicIp.txt"
NoIPlogFile="/tmp/NoIPlog.txt"


#############
### Usage ###

Usage() {

echo "Usage: $0 [-a] [-r] [-h]
-a: find the public IP and record it to no-ip.org
-r: remove $PublicIPfile and force the temporary route to be removed
-h: display Usage"
}


######################################################
### Get server's IP that will return the public IP ###

GetIPofSrv() {
ServerIP=`nslookup $Server2GetIP $NameServer | awk '/^Address/ && !(++c%2) { print $3 ; exit }'`
echo "IP address of $Server2GetIP: $ServerIP"
}


##############################
### IP syntax verification ###

CheckIPsyntax() {
Valid=$(echo $IP2Check | egrep '^[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}$');

if [ ! -n "$Valid" ]
then
echo "This IP ($IP2Check) isn't valid; exit."
exit 1
fi
}


#####################
### Add the route ###

AddRoute() {
echo "Add route for $ServerIP to $GatewayIP"
route add -host $ServerIP gateway $GatewayIP
}


########################
### Remove the route ###

RemoveRoute() {
echo "Remove route for $ServerIP to $GatewayIP"
route del -host $ServerIP gateway $GatewayIP
}


#########################
### Get our public IP ###

GetPublicIP() {
PublicIP=$(wget -O - http://$ServerIP/ -o /dev/null)
echo "The server $Server2GetIP returns the public IP: $PublicIP"
}


##############################
### Get previous Public IP ###

GetPreviousPublicIP() {
if [ ! -f $PublicIPfile ]
then
echo "$PublicIPfile not exists"
PrevPublicIP=""
else
read PrevPublicIP < $PublicIPfile
fi
}


#############################################
### Check if a public IP update is needed ###

CheckIfUpdateNeeded() {

#Comment or uncomment the line below to test with a fake IP or the real public IP
#PublicIP="1.1.1.1"

if [ "$PrevPublicIP" = "$PublicIP" ]
then
echo "This public IP is already set ; exit"
exit 0
fi
}


################################################
### Record the public IP to the dynamic name ###

RecordIP() {
echo "$PublicIP" > "$PublicIPfile"
echo "Update the host $MyHost with $PublicIP"
wget -O "$NoIPlogFile" -q --user-agent="$UserAgent" --no-check-certificate "https://$UserName:$This email address is being protected from spambots. You need JavaScript enabled to view it./nic/update?hostname=$MyHost&myip=$PublicIP"
}


############
### Main ###

while getopts arh o
do case "$o" in
a)GetIPofSrv
IP2Check=$ServerIP ; CheckIPsyntax
GetPreviousPublicIP
AddRoute
GetPublicIP
IP2Check=$PublicIP ; CheckIPsyntax
RemoveRoute
CheckIfUpdateNeeded
RecordIP
exit 0
;;
r)rm $PublicIPfile
GetIPofSrv
IP2Check=$ServerIP ; CheckIPsyntax
RemoveRoute
exit 0
;;
h)Usage
exit 0
;;
*)Usage
exit 1
;;
esac
done

Usage
exit 1

 2.2 CronTab

Il faut ensuite installé ce script dans la crontab.

Pour cela il faut éditer le fichier /etc/crontab et y rajouter la ligne suivante:

*/30    *       *       *       *       root    /volume1/homes/Oniric/script/noip.sh -a

 

Add comment


Security code
Refresh

Go to Top
Template by JoomlaShine