Using DynDNS with OVH
OVH provides rich features, one of which is a DynDNS service when you have registered a domain with them. In other words, if you have mydomain.net
registered there, then you can dynamically register an external machine on a subdomain. In my example here, I will have my home PC registering as home.mydomain.net
, which will allow me to access if from everywhere.
Configuring the OVH side
See this article on their knowledge base.
Configuring my home PC
We will be using a utility called updatedd
, which seems unfortunately to be retired. You need to make some tweaks as per explained in this article. I am providing a mirror of the updatedd 2.6 source in case the repository provided in the article disappears : updatedd_2.6.tar.gz.
The article above proposes a cron script to regularly update the OVH server with the dynamic IP of the home PC, but I have found some issues with its logic on my side, so here is my version:
#!/bin/bash ## CONFIGURATION ## # Connection to OVH DynHost username=mydomain.net-home password=SUPERSECRET host=home.mydomain.net # How to log # 1 = true, 0 = false log_change=1 log_no_change=0 log_file=/var/log/dynhost.log # To avoid error "file not found" touch ${log_file} # Get Public IP # FROM EXTERNAL WEBSITE # ip=`wget http://www.monip.org -q -O - | grep "IP :" | awk -F' : ' '{print $2}' | awk -F'<br>' '{print $1}'` # FROM LIVEBOX ip=`wget http://192.168.1.1 -q -O - | grep '<td class="value">' | awk -F "[<>]" '(NR == 3) {print $3;}'` # Get IP as defined in the DNS ip_in_dns=`dig +short $host` # Test if IPs are equal if [ "${ip}" = "${ip_in_dns}" ] then if [ "${log_no_change}" = "1" ] then echo `date +%Y%m%d-%H%M%S`: same IP in DNS \($ip\), so no need to push and change >> ${log_file} fi else if [ "${log_change}" = "1" ] then echo "`date +%Y%m%d-%H%M%S`: IPs are different (DNS : ${ip_in_dns}, host : ${ip})" >> ${log_file} /usr/local/bin/updatedd ovh -- --ipv4 ${ip} ${username}:${password} ${host} >> ${log_file} 2>&1 else /usr/local/bin/updatedd ovh -- --ipv4 ${ip} ${username}:${password} ${host} fi fi
Then just add this script to your crontab and you’re good to go.
[…] have written a bunch of scripts to automate some tasks, like for example to automate dynamic IP registration in a DNS or more commonly for backup […]