Using DDNS - Linux Web Server Development (2015)

Linux Web Server Development (2015)

Chapter 6 Using DDNS

So far, your Web server is running and the test page is available for any browser in the Internet with the following URL:

http://<router’s-public-IP-address>:8181

For example, if the public IP address of your router is 94.69.220.39, the following URL would be used:

http://94.69.220.39:8181

Recall that the router redirects all requests it receives destined for port 8181 (and also 8080 in the examples we follow in this book) to your Web server.

If your Internet Service Provider allocates static IP addresses, you can register a domain name (e.g., www.mydomain.com). This domain name will maps to the public IP address of your router using standard DNS (Domain Name Service). In the case that you have a domain name and a static IP address, you are ready to announce the URL as the following:

http://www.mydomain.com:8181

or

http://www.mydomain.com

(if we use port 80, assuming your ISP permits this)

If your ISP, however, allocates dynamic IP addresses to your router (which is typically the case for less expensive connections) or you don’t wish to pay for a domain name, you cannot use DNS and must use DDNS, Dynamic DNS. With DDNS, you can use a domain name for your Web server even if the public IP address of your server is dynamic (and therefore changes).

First, you must register with a DDNS service. In doing so, you will obtain a domain name that corresponds to the public IP address of your router at the time of registration. Every time the public IP address of the router changes, the DDNS server is notified and the domain name is updated with the new IP address. The router’s DDNS client service notifies the provider’s DDNS server of a change to its public IP address. Alternatively, if this is not a feature of the router, a DDNS client program on the Cherokee server can check for an IP address change and notify accordingly the DDNS server.

DDNS Service Registration

There are numerous DDNS service providers on the Web and choosing one is not always easy. The decision on which DDNS service provider to use will be based on the following:

● Price. A cheap service does not necessarily guarantee lack of reliability.

● Some DDNS providers allow Port Forwarding (described below).

● The level of effort required to set up the DDNS client.

If your server uses a port other than the standard HTTP port 80, you can use port forwarding. For example, if you use port 8181 instead of port 80, you could use:

my_server.ddns_provider.com

instead of:

my_server.ddns_provider.com:8181

With port forwarding, even though the port number 8181 is not included in the URL, all client requests are redirected to the public IP address of your router at port 8181. The router then passes the requests on to your Cherokee server, as described in the previous chapter with the Virtual Server service.

Dynu.com is one example of a DDNS provider:

In dynu.com’s home page, click on the Create Account link at the upper-right area of the window. Complete the form with the account details (e.g., domain name, password) and click on the Submit button.

You will receive an e-mail in the e-mail account that you provided. Click on the link included in the e-mail to activate the account by verifying your e-mail address.

The link from the e-mail sends you to the Control Panel. At a later time, you can login from the Login link next to the Create Account link by entering the e-mail address and your password and clicking then on the small gears icon in the upper-right area of the page.

To configure your DDNS options, click on the DDNS Services link. Next click on the Add button to add a new entry:

Next, complete the Host field with the host name of the domain name that you registered (e.g. webserver). Click the Add button.

The Manage Dynamic DNS Service page appears. The next time you login, your domain name will appear on the Dynamic DNS Services page and you simply click on it to go to the Manage Dynamic DNS Service page.

Note that the public IP address of your router is already detected and entered in the IPv4 Address textbox. Also the domain name (e.g., webserver.dynu.com) is also displayed. On this page, you will configure your DDNS (e.g., to enable or disable port forwarding).

Activating the Port Forwarding Service

Next, you can enable the Port Forwarding service, by clicking on the Web Redirect link of the Manage Dynamic DNS Service section. The Manage Web Redirects page appears:

At the Type drop-down menu, select Port Forwarding. In the Port text field, enter the port number on which the web server listens (e.g., 8080). Click the Add Web Redirect button.

To disable Port Forwarding from the Control Panel, select Dynamic DNS Services.

Click the Domain Name (e.g., webserver.dynu.com), which is included in the Domain Name field. This link will lead you to the Manage Dynamic DNS Service page. Click on the Web Redirect link and in the next page, Manage Web Redirects, click on the Disable Web Redirect button.

To enable Port Forwarding again, click the Enable Web Redirect button.

Installing and Configuring the DDNS Client

You must first determine whether your router provides a DDNS service and, if it does, which DDNS servers it supports. In the router’s Access Management section of the web-based interface, click on DDNS to determine if our router supports the specific DDNS server.

If the DDNS server listed is a server that you would prefer not to use, you cannot use the router to implement DDNS and must instead download a Linux DDNS client to our Cherokee server.

There are various DDNS clients available as Free/Open Source programs. Instead of randomly selecting a DDNS client, the DDNS provider will typically recommend a DDNS client. The DDNS provider will also usually detail the necessary configuration.

In dynu.com, click on the Support menu and select DOWNLOADS. The Download page appears. Click onto DDClient Typical Configuration File to find dynu.com’s suggestion for configuring a Linux DDNS client, ddclient.

ddclient is installed with the following commands at the Ubuntu Linux terminal:

$ sudo apt-get install ddclient

Throughout the installation process, a number of blue-framed screens will appear for the ddclient configuration. Since you will use an already existing configuration file, press the ESC key for each screen to bypass the screen.

Note that in order to remove ddclient you enter at the command line:

$ sudo apt-get purge --auto-remove ddclient

After the installation has completed, edit the /etc/ddclient.conf configuration file using gedit:

$ sudo gedit /etc/ddclient.conf

Paste the lines from the configuration file that we downloaded from dynu.com. Change the following fields:

login=my_domain_name

password=a_passwd

Enter also the domain name that you have registered with dynu.com:

my_domain_name.dynu.com

The following image shows ddclient.conf for the domain christos.dynu.com.

The lines that require editing are:

login=christos

password=7f6ak7e

christos.dynu.com

To support more than one domain name for your server, append to ddclient.conf the lines specific to the second domain name that were provided by your DDNS provider.

Testing the DDNS Client

To test the ddclient daemon run at the command line ddclient with the query argument:

$ sudo ddclient –query

This command should output the public IP address of your router at this specific time:

use=if, if=eth0 address is 192.168.1.101

use=if, if=lo address is 127.0.0.1

use=if, if=wlan0 address is NOT FOUND

use=web, web=dnspark address is 94.69.223.31

use=web, web=dyndns address is 94.69.223.31

use=web, web=loopia address is 94.69.223.31

use=web, web=checkip.dynu.com/ address is 94.69.223.31

You can check and with an online network tool to ensure that the IP address (94.69.223.31 in our example) is your router’s public IP address. You can also read the syslog file to find the date and time that the ddclient updated the IP address at the DDNS servers.

$ sudo cat /var/log/syslog | grep SUCCESS

An example of the command’s output is the following:

May 17 07:39:31 pc ddclient[1125]: SUCCESS: updating christos.dynu.com: good: IP address set to 94.69.223.31

May 17 07:39:32 pc ddclient[1125]: SUCCESS: updating webserver.dynu.com: good: IP address set to 94.69.223.31

You can also check ddclient’s response when the IP address of your router changes. Power-off the router for a few seconds and then start it back up. The public IP address of your router should renew. Use ddclient to find the new IP address:

$ sudo ddclient –query

The command’s output becomes:

use=if, if=eth0 address is 192.168.1.101

use=if, if=lo address is 127.0.0.1

use=if, if=wlan0 address is NOT FOUND

use=web, web=dnspark address is 79.130.93.2

use=web, web=dyndns address is 79.130.93.2

use=web, web=loopia address is 79.130.93.2

use=web, web=checkip.dynu.com/ address is 79.130.93.2

Check also the syslog file:

$ sudo cat /var/log/syslog | grep SUCCESS

The command’s output becomes:

May 17 07:39:31 pc ddclient[1125]: SUCCESS: updating christos.dynu.com: good: IP address set to 94.69.223.31

May 17 07:39:32 pc ddclient[1125]: SUCCESS: updating webserver.dynu.com: good: IP address set to 94.69.223.31

May 17 07:50:14 pc ddclient[1125]: SUCCESS: updating christos.dynu.com: good: IP address set to 79.130.93.2

May 17 07:50:15 pc ddclient[1125]: SUCCESS: updating webserver.dynu.com: good: IP address set to 79.130.93.2

Testing the Site using the Domain Name

To test your site with the new domain name obtained from dynu.com, go to tools.pingdom.com. At the Test Now text field, enter the new DDNS URL for your site:

http://christos.dynu.com

or

http://christos.dynu.com:8181

if port forwarding is not enabled in the DDNS service.

The Cherokee test page, along with some performance statistics, should appear:

Click the web page icon to zoom into the Cherokee test page: