Once again, if your ISP already gives you a static IP address, you don’t need to worry about this section.
We’ve already set up a static internal IP address for the Raspberry Pi, which means computers inside your local network will always know where to find your Pi. But what about projects that require Raspberry Pi to be connected to the Internet? If you want to build a Web server with your Raspberry Pi, people outside your network need to know where your Pi lives, which means setting a public IP that always looks the same.
I say “looks the same” because we’re really setting up a pseudo-static IP. Your ISP will continue to change the address as usual. So every time somebody connects to your Pi, the script we’re about to write will say, “Looks like the Pi has moved! Let me redirect you to the new address.”
First sign up for a free dynamic host service like DNS Dynamic. Follow the instructions and create a new nameserver like Yourserver.dnsdynamic.com.
Now go to the command line on your Raspberry Pi and install DDClient with the following line:
sudo apt-get install ddclient
We need to edit the DDClient configuration with our DDNS’s new name server:
sudo nano /etc/ddclient/ddclient.conf
Every service will have slightly different configuration, but the DDNS website should tell you what you need to do to configure this file. A standard configuration for DNS Dynamic, for example, goes like this. Copy and paste it in.
Your ISP isn’t going to just stop updating the Raspberry Pi’s IP address because of this file, however, so we need to put a daemon at the very top of this script to tell it to continually check whether or not the IP address has changed.
# check every 600 seconds
This one checks every 10 minutes, which is just good practice. If you set it up to check every second, your dynamic service may not appreciate it because you’ll be literally spamming their servers. Press Control + X to save and exit this configuration file.
After this, type:
Simply typing the name of the program will run it. It’ll continue to run as long as your Raspberry Pi is turned on. If you reboot your Pi, write “ddclient” to start running it again.
Now your Raspberry Pi is tricked out and ready for more advanced tutorials. Have fun and learn lots!