This guide will show you how to have a normal domain name that will always point to your home’s IP address, so you can access your pi from the outside world using a .tk domain name. Its basically like having dyndns.org type of name, but instead of paying for their services now…you have your own .tk name for free. Your raspberry pi will be doing the update. Every 300 seconds it will check your home’s ip address and update your .tk name with a new ip if needed.
So lets start…
Grab a free .tk domain name from http://dot.tk/ (ex: myzuperpi.tk) Make an account on the site and register a .tk name for 1 year…its totally free. Once you’ve done that then create an account at https://www.cloudflare.com/ as well.
We’ll use cloudflare’s nameservers on the dot.tk domain name then use an updater program on the pi, that will update cloudflare’s IP whenever you change IP at your house, thus changing your .tk IP at the same time.
So you have a .tk name and you’ve made a new account at cloudflare. Now we’ll hook up clourflare’s nameservers to your .tk domain.
In cloudflare, (once you log in), click at the top left corner the “Add site” button, and type in your .tk domain name.
It might not find it one the first try, since you’ve just registered it…keep trying until it does. When it allows you to press “Continue Setup”, do it. It will show you a table with some A, CNAME records with an orange cloud next to the right.
Click on the clouds to turn them off, then press continue and select the Free Website and continue again.
It will take you to a page that has some nameservers. We need the first 2 nameservers to add them at your .tk domain name. Go now to your dot.tk account (log in) and click at Domains->My domains. Then click “Manage Domain” button next to your newly created .tk name. Go to “Management Tools”, then “Nameservers”, select Custom and then copy paste the 2 names servers you got from cloudflare. You dont need nameserver3 , 4 and 5.
To recap. We’ve ‘bought’ a .tk name, that we are not forwarding to cloudflare by using cloudflare’s nameservers on it. That means that the name will now forward all traffic to cloudflare. So the only thing left is to go back to cloudflare and create a DNS record that will get updated by our updater on the pi, that will have your home IP address…So aaaaaaall the traffic from your .tk name will eventually lead to your home’s ip address.
So lets do that. Go back to cloudflare and from the top left tab click your domain name. Then click the blue button that says DNS. You should see something like this: http://s13.postimg.org/f7r549dcn/Untitled.png
If you dont see an A and CNAME record at your setup then create one. Follow the same values as my example…Thats my home IP address…It doesnt matter what you put there…Of course you can put yours, but once we start the updater it will automatically change to your home’s IP address…But do the www thing…so in case you ever host a website on your pi, it will work properly. We’ll also need an API key from cloudflare…We’ll use that for the updater to log in to cloudflare and update your IP. At the top right corner click your username and go to My Profile. Scroll down where it says API KEY and create a GLOBAL API KEY, then copy it…you’ll need it later on.
- Now here comes the Pi stuff…We’ll use a client called ddclient. This is the updater, that will automatically update your cloudflare IP whenever you change IP at your house. The one from the raspberry pi repo didnt work well for me so i had to downgrade to an earlier version. So for starters download this version of ddclient. https://onedrive.live.com/redir?resid=5A7336416C3E3C61!799&authkey=!AEn1ybXpX5XoAI4&ithint=file%2Cbz2
Now i assume you have an ftp client to connect to your pi, something like winscp or filezilla ?
Use that to connect to your pi and upload the ddclient-3.8.3.tar.bz2 file you just got…put it at /home/osmc folder…so in the end it will here: /home/osmc/ddclient-3.8.3.tar.bz2
We’ll extract the client now and set it up. Its much easier to do this with the root account on the pi instead of the osmc one…since you dont have to constantly type sudo to execute a command. So log on to your pi with putty then type this:
sudo passwd root and type in a password that you want to have for your root account. (twice). After you’ve done that, log in to your root account with:
su root and type in your root password.
Now we’ll continue with the extraction and installation. Type the following, pressing Y whenever it asks you something:
apt-get install libjson-perl libjson-any-perl libio-socket-ssl-perl bzip2
tar jxf ddclient-3.8.3.tar.bz2
chmod +x ddclient
cp ddclient /usr/sbin/
cp sample-etc_ddclient.conf /etc/ddclient/ddclient.conf
Now a text editor will open. I’ll send you an example of what to place there with Ctrl+V.
daemon=300 # check every 300 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. Works with
#use=ip, ip=127.0.0.1 # via static IP's
#use=if, if=eth0 # via interfaces
#use=web # via web
## CloudFlare (www.cloudflare.com)
You have to change these values before you copy paste it…add your values instead:
yourdomainn.tk <— your new .tk domain name
email@example.com <---- the one you use to log in cloudflare
yourapikeyhere <— the api key you got from cloudflare
yourdomainn.tk <----at the bottom of the config file…dont forget this!
Once you copy paste them, Ctlr+X, then Y, then Enter
- Now we’ll make ddclient a service to start when the pi boots.
I’ve used this guide here for that: Ddclient not working as a service (Rpi2 - OSMC alpha4)
Basically we do this:
Copy paste inside this:
Description=Dynamic DNS Client
ExecStart=/usr/sbin/ddclient -daemon 300 -syslog
Then Ctrl+X, Y, Enter again
And finally do this:
systemctl start ddclient.service
systemctl enable ddclient.service
ddclient -daemon=0 -debug -verbose -noquiet
The last command of this last bunch is an important one. You should have that command somewhere on the side. If you execute it, it will manually update your IP at cloudflare with your router’s ip but also give you information about the update. If something failed or if the ip didnt update or something. You can execute it whenever you want…dont be afraid.
This service will check every 300 seconds and see if your IP matches the one at cloudflare…if it doesnt it will update it automatically.
And you are done…you can use your .tk domain name now from anywhere in the world on a putty console (or even vnc) instead of your dynamic IP address.
Your new .tk name cant be use from your pc to connect to the pi (they are both under the same LAN network). If you want to do that you’ll have to edit your C:\Windows\System32\drivers\etc\hosts file and add a forwarding line to point to your pi’s local ip address…like so:
where …10 is the local ip of your pi.