Next: , Previous: , Up: Nastavenie systému   [Contents][Index]


3.5 Dynamic DNS mcron job

If your ISP (Internet Service Provider) only provides dynamic IP addresses, it can be useful to setup a dynamic DNS (Domain Name System) (also known as DDNS (Dynamic DNS)) service to associate a static host name to a public but dynamic (often changing) IP address. There are multiple existing services that can be used for this; in the following mcron job, DuckDNS is used. It should also work with other dynamic DNS services that offer a similar interface to update the IP address, such as https://freedns.afraid.org/, with minor adjustments.

The mcron job is provided below, where DOMAIN should be substituted for your own domain prefix, and the DuckDNS provided token associated to DOMAIN added to the /etc/duckdns/DOMAIN.token file.

(define duckdns-job
  ;; Update personal domain IP every 5 minutes.
  #~(job '(next-minute (range 0 60 5))
	 #$(program-file
            "duckdns-update"
            (with-extensions (list guile-gnutls) ;required by (web client)
              #~(begin
                  (use-modules (ice-9 textual-ports)
                               (web client))
                  (let ((token (string-trim-both
                                (call-with-input-file "/etc/duckdns/DOMAIN.token"
                                  get-string-all)))
                        (query-template (string-append "https://www.duckdns.org/"
                                                       "update?domains=DOMAIN"
                                                       "&token=~a&ip=")))
                    (http-get (format #f query-template token))))))
         "duckdns-update"
         #:user "nobody"))

The job then needs to be added to the list of mcron jobs for your system, using something like:

(operating-system
 (services
  (cons* (service mcron-service-type
           (mcron-configuration
             (jobs (list duckdns-job ...))))
         ...
         %base-services)))