No matter which services your Raspberry Pi is running you will want it to have a static address for global access, which is done by setting up a dynamic DNS service.
In this guide I describe the steps you need to complete in order to set up a free dynamic DNS service on your raspberry Pi (yes, this also works for Raspberry Pi 2), so that you no longer have to worry about whether your external IP address changes once in a while. Whenever it changes, the dynamic DNS makes sure that your chosen website URL will always resolve to the current external IP of your Raspberry Pi.
As I set up my Raspberry Pi Mumble server, I needed to have a static web address for everyone else to access it. It would be very troublesome having to tell everyone about it every time my dynamic IP changed.
After a bit of research I decided to go with the free service provided by dnsdynamic.org, as it is both free to use and easy to set up.
Step by step guide
Here is how to set up the free dynamic DNS service.
It should work just as well with other linux systems than Raspbian on the Raspberry Pi.
- Create a user profile at the dnsdynamic website.
- Choose to “add a new domain” when logged in on the dnsdynamic website.
- Open a terminal on your Raspberry Pi and install the update service:
sudo apt-get install ddclient
- If you are presented with a configuration wizard, just go through it and put in some random text.
(We will overwrite this in the configuration file anyway)
- Edit the configuration file
/etc/ddclient.confand replace everything in it with this:
# Configuration file for ddclient generated by debconf
daemon=60 # check every 60 seconds
syslog=yes # log update msgs to syslog
mail=root # mail all msgs to root
mail-failure=root # mail failed update msgs to root
pid=/var/run/ddclient.pid # record PID in file.
ssl=yes # use ssl-support.
use=web, web=myip.dnsdynamic.com # get ip from server.
server=www.dnsdynamic.org # default server
login=YOUR-LOGIN # your login
password=YOUR-PASSWORD # your password
- Edit the three placeholders YOUR-LOGIN, YOUR-PASSWORD and YOUR-DOMAIN and replace them with your own.
- Save the changes made to the config file, and restart the Raspberry Pi.
- Remember to configure your router to forward the necessary ports to your Raspberry Pi.
(port 80 for web server, 21 for ftp, 64738 for default mumble, etc.)
If everything is working as intended, you should see the global IP of your Raspberry Pi automatically set on the dnsdynamic website, under Manage -> Edit domains.
Now you can access your Raspberry Pi services at the domain name you chose with dnsdynamic.org instead of your global IP address. Should your global IP change, the daemon will automatically detect this and make the domain point to the new global IP instead. The users will never know that the IP has changed, since they only see and use the domain name.
If you have another domain you want to use instead of the ones provided by dnsdynamic, simply configure the DNS of your other domain to do a CNAME forward to your dnsdynamic domain.
Checking for IP changes every 60 seconds may be a bit overkill in some cases. You can change the
daemon=60 to eg.
ddclient.conf to check for IP changes every 5 minutes instead.
I had this setup working until my network provider upgraded my modem.
Since then, I’ve not been able to ssh to my Raspberry Pi using the dyndns address anymore.
I can ssh to it on my LAN, and it does update its address on the dyndns site.
How can I debug the issue?
Also, I got one attack record (?) in /var/log/auth.log:
Oct 30 16:23:39 Berry314 sshd: Invalid user admin from 22.214.171.124
Does this mean that some packets get forwarded?
Remember to forward the necessary ports through your new modem. It would seem that there is some hole through. What about if you try to SSH directly to your current public IP?
Note that you may experience some inconsistencies if you try to connect from within your home network to your public IP.
Very useful! Thank you! I have one more question, I wish you can help me! I bought my Raspberry PI one year ago, and till now everything was okay with it. I have never complained on it before! Last week I started to remark that red light-emitting diode became blink! I know that it is not normal and sometimes it can just stop light! I don’t know what to do?My friend said that it can happen time to time and the best way is to replace light-emitting diode but I am sure that it is very difficult and for me unreal. The first reason is that I can’t find exactly red light-emitting diode. I am used to buy hardware here hardware.nu but unfortunatly they have nothing! Also I looked at amazon but nothing too!(((((((
Just did the same with DuckDNS.org, took 2 minutes to register and setup on my Raspian
I have problem register to the https://www.dnsdynamic.org/ i make an account and i dont get a confirmation email
Have you checked your spam folder?
Otherwise I can’t really help, as I am not involved with dnsdynamic.
I had no problems when registering.
You may use this quick yet simple DDNS alternative that doesn’t even require any registration, at : http://www.iprekt.com
The API is pretty much compatible with the tutorial above.
Tried corporate email as well as hotmail, no email from them after over 24 hours.
Same here, no email
I’m getting an error when trying to ssh on to the server.
ddclient: WARNING: cannot connect to myip.dnsdynamic.com:80 socket: IO::Socket::INET: Bad hostname ‘myip.dnsdynamic.com’
any ideas why?
Try changing it to “myip.dnsdynamic.org”
Try port forwarding
Good stuff Mikkel…very good.
I´ll test it today on my Raspberry Pi, but it seems to be a good configuration.
I notice that line “server=www.dnsdynamic.org, \” may be deleted, isn´t it? Because you have specify it before.
Another question: mail=root sends mail msgs to root but, what messages?
Thanks a lot
I can see what you mean with the line appearing twice. I haven’t tried deleting one of them. If you come to a conclusion, please let me know the result.
I haven’t used the mail functionality, but i believe that you can have ddclient send out an email to given adresses eg. every time a new IP is registered.
You would probably have to configure e-mail settings in linux directly for the user, or just add an e-mail address to the user profile. I don’t know for sure.
Glad you find my post useful
Thx for the info on how to setup the ddns which I’ve done it.
Now the challenge is, it never update to the ddns site every time the IP changed.
Any solution on this matter?
Appreciate your reply very much!
You need to get the ddclient installed and running on your Raspi, so that it can verify the current public IP at the time interval you set.
If the ddclient has internet connection and is correct set up, it will then automatically change the setting in the profile on dnsdynamic.
Any problem in the configuration of the ddclient will result in failure to update the ddns entry automatically.
Note that this method only applies to the public IP, not to your local 192.168.x.x
Hope this helps… =)
Working fine on rasbian wheezy using: ddclient 3.8.0-11.5
After following this guide:
it made ssh over LAN easy. Thanks again!
I am getting warnings that the client from dnsdynamic (windDNSdynamic.exe) is malicious. This website seems to confirm it: http://www.coolcomputing.com/article.php?sid=4618
Can anyone confirm if this true?
I don’t know anything about the windows client.
I haven’t used it, since you do not need it if you just want to use their dynamic DNS service on a Linux system.
All Linux user should thus be safe already, but i certainly hope that their windows client does not contain anything malicious.
Maybe it is flagged because it gathers information of your network connection (which it needs in order to handle the dynamic DNS)?
If anybody knows, please share with the rest of us =)
Thank you very much for this great explanation … works perfectly.
One question though. I have my Raspi switched on all the time and of course the Ip address changes quite regularly.
Where could I find, or how could I do, so as to put the new Ip address to the dnsdynamic website? Looks like it cannot to it by itself and a reboot usually solves the situation … which I do not want to do!
Thank you for your comments,
If set up correctly, the daemon will submit the current IP of your Raspi at a predetermined interval. You define the interval in the config file as described.
Usually your IP does not change very often, as long as you keep your main router turned on as well…
Thanks for the tips! I used this guide to set-up my RaspberryPi (http://cladlab.com/programming/microcontrollers/raspberry-pi) with dynamic DNS. This is one of the easiest guides to doing so on the internet!
Great post. Love RPI. I am using https://dns4e.com/ to manage my dynamic IPs. It is very simple to add one curl command to crontab like this one:
curl ‘https://api.dns4e.com/v7/rpi.dns4e.net/a’ –user ‘PublicKey:SecretKey’ -X POST and it updates the IP without any custom packages isntalled.
Check out this simple steps for setting up Dynamic DNS for free (using FreeDNS) on your Raspberry Pi or any Unix system (Debian based)
You can also use No-IP for free dynamic DNS.
Hey, I still can’t connect to my pi over the internet. It works fine over the local network (with local ip). Im a complete beginner with this stuff, would I need to forward my ports ? if so how would I do that ?
Several things could be the issue, but if you haven´t done any port forwarding that is probably it.
My guess is that your Raspberry Pi is connected to a switch or router alongside your PC, etc.
Seen from outside your local network ( from the internet) you will have only a single IP address, which is that of your router.
If you do not configure your router to do so, it won’t know which one of the attached devices it should forward specific incoming traffic to.
You will thus need to log in to your router or switch and configure it to forward all traffic on each port for which it has a service (eg. port 80 for web server, 21 for FTP, 64738 for default mumble).
A good place to start is by finding your router on this list and follow the guide: http://portforward.com/english/routers/port_forwarding/routerindex.htm
Port forwarding can be a pain to set up correctly, but give it a try and see if it works for you.