Configuring DNS services (revision 2)

Introduction

This page describes how Alexis Huxley installed and configured his DNS server and no-ip dynamic DNS updater.

Procedure

  1. If needed, set up an authoritative DNS server as follows:
    1. Set some environment variables used by this procedure:
      AUTH_ZONES="<zone#1> <zone#2> ..."
      #  E.g. AUTH_ZONES="pasta.net 1.168.192 3.168.192 10.168.192"
    2. Install the packages required for the DNS server by running:
      apt-get install bind9
    3. Initialise the local configuration by running:
      > /etc/bind/named.conf.local
      #  Stop lots of IPv6 errors log entries by disabling IPv6 support
      echo "OPTIONS=\"-u bind -4\"" >> /etc/default/bind9
      perl -pi -e 's@(listen-on-v6)@// $1@' /etc/bind/named.conf.options
      > /etc/bind/named.conf.local
      
    4. Generate /etc/bind/named.conf.local for the zones by running:
      {
          for AUTH_ZONE in $AUTH_ZONES; do
              [[ $AUTH_ZONE =~ ^[0-9] ]] && ZONE_SUFFIX=.in-addr.arpa || ZONE_SUFFIX=
              echo "zone \"$AUTH_ZONE$ZONE_SUFFIX\" {"
              echo "    type master;"
              echo "    file \"/etc/bind/db.$AUTH_ZONE\";"
              echo "};"
              echo
          done
      } >> /etc/bind/named.conf.local
    5. Creating the corresponding zone files, as in these examples:
      ditalini# head /etc/bind/db.pasta.net
      $ORIGIN pasta.net.
      $TTL 1h          
      pasta.net.               IN  SOA   ns.pasta.net. root.pasta.net. ( 1487674547 1d 2h 4w 1h )
      pasta.net.               IN  NS    ditalini    ; cannot be 'ns' since CNAME illegal
      pasta.net.               IN  MX    10 fusilli     ; cannot be 'mail' since CNAME illegal
      
      filer                    IN  CNAME fettuce-on-storage-net
      gateway                  IN  CNAME fregula
      i2p                      IN  CNAME gigli
      imap                     IN  CNAME fusilli
      ditalini# head /etc/bind/db.1.168.192
      $ORIGIN 1.168.192.in-addr.arpa.
      $TTL 1h          
      1.168.192.in-addr.arpa.  IN  SOA   ns.pasta.net. root.pasta.net. ( 1487674547 1d 2h 4w 1h )
      1.168.192.in-addr.arpa.  IN  NS    ditalini.pasta.net.
      
      1                        IN  PTR   fregula.pasta.net.
      2                        IN  PTR   corzetti.pasta.net.
      3                        IN  PTR   ditalini.pasta.net.
      6                        IN  PTR   fiori.pasta.net.
      7                        IN  PTR   torchio.pasta.net.
      ditalini#
    6. In /etc/resolv.conf, make sure the nameserver is set to 127.0.0.1.
    7. Run:
      service bind9 restart
  2. If you wish to access your systems’ “public” hostnames from inside the home network and you just set up an authoritative DNS server then:
    1. Edit /etc/bind/named.conf.options and set:
      options {
          ...
          response-policy { zone "rpz"; };
      };
    2. Edit /etc/bind/named.conf.local and add the stanza:
      zone "rpz" {
          type master;
          file "/etc/bind/db.rpz";
      };
    3. Create /etc/bind/db.rpz containing something like:
      $TTL 1h          
      @  IN  SOA   ns.pasta.net. root.pasta.net. ( 1487674547 1d 2h 4w 1h )
      @  IN  NS    localhost.    ; cannot be 'ns' since CNAME illegal
      
      ; redirect externally-valid names to internal IPs
      www.pasta.freemyip.com     IN CNAME www.pasta.net.
      jira.pasta.freemyip.com    IN CNAME www.pasta.net.
      svn.pasta.freemyip.com     IN CNAME www.pasta.net.
      repo.pasta.freemyip.com    IN CNAME www.pasta.net.
      ...
      ; blacklist
      google-analytics.com       IN CNAME .
      *.google-analytics.com     IN CNAME .
      rdata.io                   IN CNAME .
      *.rdata.io                 IN CNAME .
      udp.dog                    IN CNAME .
      *.udp.dog                  IN CNAME .
      
      
    4. Run:
      service bind9 restart
  3. If needed, set up a dynamic DNS updater as follows:
    1. Run:
      apt-get install inadyn
    2. Edit /etc/default/inadyn and set:
      RUN_DAEMON="yes"
    3. Edit /etc/inadyn.conf and modify/add the following settings:set username, password, etc. Be sure to add also:
      #logfile /var/log/inadyn/inadyn.log
      syslog
      system default@no-ip.com
      username <your-no-ip.com-login>
      password <your-no-ip.com-password>
      alias <your-1st-no-ip-hostname>
      alias <your-2nd-no-ip-hostname>
      ...
      forced-update 86400
      

      (The last entry should prevent regular mails from no-ip.com asking telling you hostnames are expiring.)

    4. Run:
      systemctl restart inadyn

See also