DHCP / DNS Setup

First install or ensure already installed the DNS server software: “sudo apt install bind9”

Next check the named.conf configuration file, “less /etc/bind/named.conf”. This can remain as default as below. However the configuration files noted there in will need to be set up. We will copy the existing files to default:

  • sudo cp /etc/bind/named.conf.options /etc/bind/default.named.conf.options
  • sudo cp /etc/bind/named.conf.local /etc/bind/default.named.conf.local
  • sudo cp /etc/bind/named.conf.default-zones /etc/bind/default.named.conf.default-zones

sudo vim /etc/default/bind9 or sudo vim /etc/default/named, set following parameter: OPTIONS=“-u bind -4”

The /etc/bind/named.conf is not changed, and should look as below.

// Default contents of /etc/bind/named.conf
// This is the primary configuration file for the BIND DNS server named.
// Please read /usr/share/doc/bind9/README.Debian.gz for information on the
// structure of BIND configuration files in Debian, *BEFORE* you customize
// this configuration file.
// If you are just adding zones, please do that in /etc/bind/named.conf.local

include "/etc/bind/named.conf.options";
include "/etc/bind/named.conf.local";
include "/etc/bind/named.conf.default-zones";

Next modify the named.conf.options configuration file, sudo vim /etc/bind/named.conf.options, as noted below.

options {
  directory "/var/cache/bind";
  auth-nxdomain no; # conform to RFC1035
  forwarders {;;;
  allow-query {
  allow-transfer {
    // listen-on-v6 { any; };

The forwarders section contains the DNS servers to be checked if this DNS does not have the record. I have been using OpenDNS to allow some free security screening, IP and I have stop using these. IP, Quadnine provides some protection bad web sites. Similar for and from Another common option is to use Google DNS at and I avoid using Google products as there is something unclean about free services that extra value by tracking you.

Next create a cryptographic key file using sudo /usr/sbin/rndc-confgen -a, note that this command can take quite some time to complete, a number of minutes. The command produces a key file /etc/bind/rndc.key.

key "rndc-key" {
  algorithm hmac-md5;
  secret "LBLC2Dg8v6hYNE/ecnd6Ag==";

Configure the DNS zones sudo vim /etc/bind/named.conf.local

key "rndc-key" {
  algorithm hmac-md5;
  secret "LBLC2Dg8v6hYNE/ecnd6Ag==";

zone "kptree.net" {
  type master;
  file "/var/lib/bind/db.kptree.net";
  allow-update { key rndc-key; };

zone "168.192.in-addr.arpa" {
  type master;
  file "/var/lib/bind/db.168.192";
  allow-update { key rndc-key; };

Modify the forward lookup zone definition file sudo vim /var/lib/bind/db.kptree.net

; This line indicates that the object we're configuring below (in this case,
; kptree.net) has its origin at the "." domain.  "." is the root domain
; from which all the TLDs branch.
; Note the comment character is ; not the usual #

; Next line defines the DNS time-to-live setting
$TTL 907200    ; 1 week 3 days 12 hours

; The next set of lines are the "Start of Authority" record and define
; important info about the domain. In my case, we're defining kptree.net
; that router.kptree.net is its source host, and webmaster@kptree.net
; and saying is the domain maintainer. For the e-mail address, we use a 
; dot instead of an @.
; The lines after that define the zone serial number, which is used to 
; keep track of when the zone file was modified, and then some interval 
; which you can leave as default.
kptree.net   IN SOA  router.kptree.net. root.kptree.net. (
        2019072101   ; serial
        10800        ; refresh (3 hours)
        3600         ; retry (1 hour)
        604800       ; expire (1 week)
        38400        ; minimum (10 hours 40 minutes)
; Next, we define the hosts necessary to make the domain function. First, 
; we add an "NS Record" to define the domain's name server...
    NS  router.kptree.net.

; ...then an "A Record" for the domain server's IP address...
    A ; This is the LAN address of the html server
                     ; that is hairpin NATed

; ...and finally "MX Records" so that e-mail for the domain's e-mail 
; addresses goes to the right place.
    MX  00 mail.kptree.net.
; Now we're ready to begin adding hosts, but first we need another origin
; statement to indicate that the hosts added below originate not from ".", 
; like the domain itself; rather, they originate from "kptree.net".
$ORIGIN kptree.net.
; Now we add A records for the non-DHCP hosts in the domain:
router        A
;switch       A  ; This manage switch was bricked a while ago.
kptreeserver  A
mediaserver   A
wiki          A
kpts          A
cloud         A
www           A  ; www is directed to the html server
wwwserver     A
;photo        A  ; photo is directed to the html server
;photoserver  A
mail          A  ; mail is directed to the html server
mailserver    A
; There seems to be no white space allowed before the name.

Note: To allow all LAN traffic to correctly flow to the html server and reverse proxy to sub-domain servers the DNS origin and all sub-domains must point to the main html server.

Define the reverse zone, sudo vim /var/lib/bind/db.168.192

# Again, we have an origin record and a TTL entry...
$TTL 907200    ; 1 week 3 days 12 hours

; note the name of the reverse domain: "db.168.192". This
; is a special name format used only by reverse lookup domains.
168.192.in-addr.arpa  IN SOA  router.kptree.net. admin.kptree.net. (
                         2017072101      ; serial
                         10800           ; refresh (3 hours)
                         3600            ; retry (1 hour)
                         604800          ; expire (1 week)
                         38400           ; minimum (10 hours 40 minutes)
                         NS  router.kptree.net.
; Just like above, we now set our origin away from "." to the actual domain
; name, which is "1.168.192.in-addr-arpa", and then we add records. However,
; this time, we're adding "PTR records", or pointer records.
$ORIGIN 1.168.192.in-addr.arpa.
$TTL 259200    ; 3 days
    1       PTR router.kptree.net.
;   3       PTR switch.kptree.net.         ; This managed switch is bricked.
    5       PTR kptreeserver.kptree.net.
    10	    PTR kpts.kptree.net.
    12      PTR wwwserver.kptree.net.
    12      PTR www.kptree.net.
    12      PTR kptree.net.
;   17      PTR photoserver.kptree.net.    ; not used at the moment
;   12      PTR photo.kptree.net.
    18      PTR mailserver.kptree.net.
    12      PTR mail.kptree.net.

If and of the above files are changed the serial number should be incremented up before updating the the DNS service, “sudo systemctl restart bind9”. A common technique is to use the date followed by a small single or double digit number, e.g. 2017072101.

The configuration file can be tested with:

  • sudo named-checkconf /etc/bind/named.conf

The zone files checked with:

  • sudo named-checkzone 168.192.in-addr.arpa /var/lib/bind/db.168.192 for the reverse zone file.
    • It is important that the first input parameter 168.192.in-addr-arpa matches the reverse address used in the SOA address used. The subsequent origin statements can be for lower address ranges, e.g. $origin 1.168.192.in-addr.arpa..
    • Again note the following fullstop after the origin address.
  • sudo named-checkzone kptree.net /var/lib/bind/db.kptree.net for the forward zone file.

If not using IPv6 bind may still look for IPv6 unnecessarily filling up log files. To prevent perform the following:

  • sudo vim /etc/default/bind9
  • add the -4 in the line: OPTIONS=“-u bind -4”
  • Also ensure to comment out “listen-on-v6 { any; };” in the file sudo vim /etc/bind/named.conf.options

Almost all ways caused by manually editing the zone file, which causes it to become out of sync with the automatic DHCP update. Solution is to:

  • Stop bind9 (sudo systemctl stop bind9)
  • Delete the problem zone file ending ing .jnl. It can be found in the same directory as the zone files: (/var/lib/bind/)
  • Then start bind9 (sudo systemctl start bind9)

Before performing a manual update on a zone file use rndc freeze before editing and rndc thaw after. See man rndc for information on his command.

First install or ensure already installed the DHCP server software: sudo apt install isc-dhcp-server

Next edit the dhcp configuration file: sudo vim /etc/dhcp/dhcpd.conf

ddns-updates on;  
ddns-update-style interim;  
update-static-leases on;

key rndc-key { algorithm hmac-md5; secret LBLC2Dg8v6hYNE/ecnd6Ag==;}

allow unknown-clients;
use-host-decl-names on; 
default-lease-time 1814400; #21 days
max-lease-time 1814400; #21 days
log-facility local7;

# kptree DNS zones
zone kptree.net. {  
    primary localhost; # This server is the primary DNS server for the zone
    key rndc-key; # Use the key we defined earlier for dynamic updates
zone 1.168.192.in-addr.arpa. {  
    primary localhost; # This server is the primary DNS server for the zone
    key rndc-key; # Use the key we defined earlier for dynamic updates

# kptree LAN scope
subnet netmask {  
    option subnet-mask;
    option routers;
    option domain-name-servers;
    option domain-name "kptree.net";
    ddns-domainname "kptree.net.";
    ddns-rev-domainname "in-addr.arpa.";

# kptree.net groups
group {

    # Printer #1 Epson WF7725
    host printer1.kptree.net {
        hardware ethernet 9C:AE:D3:F0:C3:E7;
        ddns-hostname "printer1";

    # Windows 10 Virtual Machine
    host vwin.kptree.net {
        hardware Ethernet 52:54:00:27:34:F4;
        ddns-hostname "vwin";

   # Karl's iPhoneXS
    host karlPhone.kptree.net {
        hardware ethernet F0:99:B6:45:6C:F4;
        ddns-hostname "karl-phone";

   # Karl's iPadMini4
    host karliPad.kptree.net {
        hardware ethernet 04:52:F3:1C:31:27;
        ddns-hostname "karl-ipad";

  # Eka's iPhone12
    host Eka-iPhone12.kptree.net {
        hardware ethernet 44:90:BB:62:D2:2A;
        ddns-hostname "Eka-iPhone12";

  # Karl's iPad air
    host karliPadair.kptree.net {
        hardware ethernet 34:31:8F:5F:16:A6;
        ddns-hostname "karl-ipadair";

  # Karl's work
    host karl-ugl.kptree.net {
        hardware ethernet 5C:80:B6:A8:AE:1C;
        ddns-hostname "karl-ugl";

    # Henry's iphone
    host henry.iphone.kptree.net {
        hardware ethernet 6c:4d:73:12:99:f1;
        ddns-hostname "henry-iphone";

    # Willem's iphone
    host willem.iphone.kptree.net {
        hardware ethernet 64:c7:53:7b:01:2f;
        ddns-hostname "willem-iphone";
    # KPTreeServer1 IPMI
    host kpts1-ipmi.kptree.net {
        hardware Ethernet 00:25:90:8B:D9:DB;
        ddns-hostname "kpts1-impi";
    # Kptreeserver2 IPMI
    host kpts2-ipmi.kptree.net {
        hardware Ethernet 0C:C4:7A:F5:0E:F7;
        ddns-hostname "kpts2-impi";
    # KPTreeRouter IPMI
    host kptr-ipmi.kptree.net {
        hardware Ethernet 00:C4:7A:9F:34:41;
        ddns-hostname "kptr-ipmi";
    # APS Solar Energy Management Unit
    host aps-ema.kptree.net {
        hardware Ethernet 80:97:1B:00:36:BA;
        ddns-hostname "aps-ema";
    # OpenSprinkler
    host sprinkler.kptree.net {
        hardware Ethernet 00:69:69:2D:31:00;
        ddns-hostname "sprinkler";
    # Study Desktop - dt1
    host dt1.kptree.net {
        hardware ethernet 00:d8:61:34:dc:0e;
        ddns-hostname "dt1";

    # Study Desktop - dt1-wifi
    host dt-wifi-1.kptree.net {
        hardware ethernet F4:D1:08:A6:96:72;
        ddns-hostname "dt-wifi-1";
    # Erich Desktop - sdt25
    host edt25.kptree.net {
        hardware ethernet 00:8e:25:79:05:cc;
        ddns-hostname "sdt25";
    # Henry's work
    host henry-desk.kptree.net {
        hardware ethernet 30:5A:3A:82:9D:35;
        ddns-hostname "henry-desk";
    # Study Desktop - sdt1-wifi
    host sdt-wifi-1.kptree.net {
        hardware ethernet 8C:1D:96:94:AD:13;
        ddns-hostname "sdt-wifi-1";

    # Study Desktop - sdt25
    host sdt25.kptree.net {
        hardware ethernet 1C:69:7A:D2:FD:91;
        ddns-hostname "sdt25";

    # RPi 1
    host RPi1.kptree.net {
        hardware ethernet E4:5F:01:3B:55:6F;
        ddns-hostname "RPi1";

    # WiFi Access Point #1
    host wifi-ap1.kptree.net {
        hardware Ethernet 80:37:73:EC:D3:1E;
        ddns-hostname "wifi-ap1";
    # WiFi Access Point #2
    host wifi-ap2.kptree.net {
        hardware Ethernet C0:FF:D4:8B:24:FE;
        ddns-hostname "wifi-ap2";


The configuration file can be tested with: sudo dhcpd -t

Restart the DHCP and DNS servers to update for latest configurations changes. DNS: sudo systemctl restart bind9 and DHCP: sudo systemctl restart isc-dhcp-server.

To see active leases use command sudo dhcp-lease-list.

ISC has stopped supporting ISC-DHCP client and relay versions as of 2022 and indicated that they plan to eventually stop support of server version. They seem to recommend migration to ISC-Kea, the ISC-DHCP replacement.

The default isc-dhcp-server configuration files is: sudo vim /etc/default/isc-dhcp-server. Ensure the interface(s) that the DHCP server is to server requests upon is indicated, for example:

  • INTERFACESv4=“br0”
  • INTERFACESv6=“br0”

Unfortunately the log / journal for isc-dhcp-server contains the following comment for each system interface that is not assigned in /etc/default/isc-dhcp-server. This is a warning, not an error! As such it can generally be ignored.

No subnet declaration for eno4 (no IPv4 addresses).
** Ignoring requests on eth1.  If this is not what
   you want, please write a subnet declaration
   in your dhcpd.conf file for the network segment
   to which interface eno4 is attached. **


ipv6 requires router advertisement to be functional to operate correctly. In Linux the radvd program performs this function and can be set up independently or with dhcp. The radvd daemon provides basic advertisement functionality, dhcp6 can give additional functionality.

  • sudo apt install radvd
  • sudo vim /etc/radvd.conf
  • sudo systemctl status radvd.service
  • /mnt/shared/www/dokuwiki/data/pages/linux_router/dns_dhcp.txt
  • Last modified: 2022-07-09 Sat wk27 10:09
  • by baumkp