IÂ look after a server which is connected to some temperature sensors on a remote site. The site is connected to the internet via a RADSL link on the end of 1.5km of very old copper cable. The reliability of the connection is weak at best and the dynamically assigned IP address tends to change every time the connection drops which can be several times a day.
I recently updated the server from Ubuntu 13.10 to Ubuntu 14.04 Long Term Support which, as it is supported until 2019, should see out the antiquated hardware’s days
In order to communicate with the server remotely, I need to know the current public IP (dynamically assigned) so I need to run a dynamic DNS client on the server to update a remote service. The service I chose for this purpose is No-IP. They offer a free basic DDNS account which meets my needs.
Client wise, I have previously (some years ago) used ddclient to update the IP address to No-IP but have more recently struggled to get the configuration working reliably.
Instead, I now use the NoIP2 client in the following fashion:
First of all, working locally on the server (because that ADSL connection really is that bad!) I download the NoIP2 client:
wget http://www.noip.com/client/linux/noip-duc-linux.tar.gz
Then I extract the archive and cd to the resulting directory:
tar -xvf noip-duc-linux.tar.gz
cd noip-2.1.9-1
The directory may differ if the noip2 client version number is updated.
Now I install the client using:
sudo make install
Next, the client needs to be configured. You’ll need the username and password you selected when you signed up for your No-IP DDNS user account.
sudo /usr/local/bin/noip2 -C
The -C flag tells the installed client to create a new configuration where you enter:
- Your username (email address for No-IP account)
- Your password (the one for the above)
- The interval (in minutes) that you wish to update your public IP address to No-IP
- A command to execute when the update is successful (you can leave this blank)
At this point, I have a working client that will update your public IP to No-IP. Note that you may need to open port 8245 (outbound) on your router if you have a restrictive outbounds ports setup.
However, if the power on the remote site goes down (and it often does, especially during storms) the server will reboot but there is nothing to tell it to restart the noip2 client.
To remedy this, I create a new file in init.d using the nano text editor:
sudo nano /etc/init.d/noip
I add the following to the file (referenced in the README):
#! /bin/sh
case "$1" in
start)
echo "Starting noip2"
/usr/local/bin/noip2
;;
stop)
echo -n "Shutting down noip2"
for i in `noip2 -S 2>&1 | grep Process | awk '{print $2}' | tr -d ','`
do
noip2 -K $i
done
;;
*)
echo "Usage: $0 {start|stop}"
exit 1
esac
exit 0
The Ctrl-x to exit nano and y to save the file.
I need to make the script executable so I issue:
sudo chmod 755 /etc/init.d/noip
To tell the system it needs to run the script after booting, I open up and edit rc.local
sudo nano /etc/rc.local
Find the line that contains exit “0” and on the line above add:
/etc/init.d/noip start
Again, Ctrl-x to exit nano and y to save.
Now when you reboot your server, the noip2 service should be running.
You can check whether it is running by issuing:
ps aux | grep noip2
You should see the noip2 service listed in the result.
After the update interval that you set when you configured the No-IP client, you should be able to reach services on your server from the no-ip dynamic hostname that you are assigned ie: your-noip-name.no-ip.com. If you’re unsure of this name, you can check it by logging into your No-IP account and looking it up. Don’t forget, you may need to open the relevant ports on your router to match the services you’re trying to reach on your server.
This should provide a relatively simple and free alternative to paying for a fixed ip address for your home or remote Ubuntu 14.04LTS servers. Remember that in order to keep your NoIP hostname, you need to update your IP ever thirty days at the latest or the hostname is released for re-use. Just keep the noip2 client going at a regular update interval and this should not be a problem.