- Raspberry Pi 2 Server Essentials
- Piotr J.Kula
- 699字
- 2021-07-16 11:10:06
Dynamic DNS
Dynamic DNS is a way of updating name records for a public DNS. Paid solutions usually offer real-time updates and free services have a minimum time before the change is published.
I have been using the paid service by NO-IP, which is fairly priced for the features it provides. It also offers free domains and services. It also provides clients for many operating systems, including a Raspbian Linux-compatible client. You may use any service you like as the protocol is the same for everybody.
Installing a client
I have a premium account registered with NO-IP. I allocated a subdomain called pi.kula.solutions. It automatically detected my public IP and set the record of the domain accordingly.
Tip
Visit http://www.mxtoolbox.com to verify live changes to domain name records. It also has several other useful tools.
Once you have created a dynamic DNS account, you can install the client on the Raspberry Pi. During the installation, you will be asked for your credentials and which domains to update.
The commands to install a client are as follows:
mkdir /home/pi/noip cd /home/pi/noip wget http://www.no-ip.com/client/linux/noip-duc-linx.tar.gz tar vzxf noip-duc-linx-tar.gz cd noip-{version} sudo make –j4 sudo make –j4 install
After running the make
installation, you will be prompted to log in with your No-IP account username and password. The interval must be 5 minutes or more. You can now start the service:
sudo /usr/local/bin/noip2
You now have a domain name that points to your home IP address. As we progress through this book, you might want to test various applications, and to do this, you will need to open ports on your router.
Unfortunately, configuring your router is not part of this book as each vendor handles this differently. Consult the manual that came with your router to learn how to open and forward ports. Opening unnecessary ports can put you at a higher risk of being hacked.
The free Dynamic DNS domain workaround
You might not like the domain names provided by the Dynamic DNS providers, or you may not be able to afford a premium service. Instead, you may want to use a domain that you already own but is hosted somewhere else. I own another domain that is not registered with NO-IP called http://www.piotrkula.com. I will use this as an example to access my Raspberry Pi using http://pi.piotrkula.com/
with a free NO-IP domain such as http://randomname.no-ip.me.
Log in to your domain name DNS panel, and add a new subdomain. Edit the DNS records and make sure that they have absolutely no A
records associated with them. You will need to add a new CNAME record and the value; in my case, it is randomname.no-ip.me.
Now the http://pi.piotrkula.com/
domain tells visitors to take a look at the randomname.no-ip.me DNS record instead. The visitor will find an A
record at NO-IP, and this will tell them the correct IP address, which is your home IP with port 80 forwarded to the Raspberry Pi. This is NOT a redirect and the top domain name will NOT change. Visitors will not even know you are using a dynamic DNS unless they inspect your private domain record and track down that CNAME
belongs to a dynamic DNS company. But as long as the domain works, there is no reason to inspect it.
The only drawback of using this workaround is speed. Whenever a visitor looks up the DNS records for the first time, it might take several seconds before a connection is established. After the first request, things go smoothly as the client usually caches the IP for the duration of the session, regardless of what TTL is set on your A
record. Every new session might experience this delay as TTL forces the client to read the DNS again. Some dynamic DNS providers might even deliberately slow down DNS lookups in the hope that you will upgrade to premium DNS servers for a premium service. As far as I know, NO-IP has never done this and performed really fast, even when I used it for free domains.