Quick DNS install

by Mark Nielsen
Copyright May 2023

Quick DNS install

The purpose of this document is to setup your own DNS server, have your servers or local server point it to for resolution, required for some services, like LDAP, and to use in our TestEnv.



This is for Ubuntu.

For this document, replace with the ip address of your computer.

   # log in as root, this assumes sudo is setup from your account. 
sudo bash
   # if you can't sudo : su -l root
    # make sure your systems is up to date
apt-get update 
apt-get upgrade 
apt-get dist-upgrade

    # install the server and utilities

apt-get -y install bind9 dnsutils

   # Save the original copy and make a new one. 
mv /etc/bind/named.conf.options /etc/bind/named.conf.options_ORIG

   # Replace W.X.Y.Z with theip address found at
   # grep ^nameserver /var/run/systemd/resolve/resolv.conf | grep -v 127
   # in the next echo command. 
   # or edit the file after and change it. 
echo 'options {
   directory "/var/cache/bind";
   forwarders {
   ' > /etc/bind/named.conf.options
   for i in `grep ^nameserver /var/run/systemd/resolve/resolv.conf | grep -v 127 | cut -d' ' -f2` ; do
echo "$i; " >> /etc/bind/named.conf.options
echo ";
   	dnssec-validation auto;
	listen-on-v6 { any; };
" >> /etc/bind/named.conf.options

   # Make the files for local zone.
   # The first adds the zone and what config file to use.
   # The second is the config file with the DNS entries for our zone. 
   # The third command adds to /etc/hosts just in case DNS does not work.

echo '
   zone "local" {
type master;
file "/etc/bind/db.local2";
   ' >> /etc/bind/named.conf.local

echo '
$TTL    604800

@       IN      SOA     ldap.local. root.local. (
                              3         ; Serial
                         604820         ; Refresh
                          86600         ; Retry
                        2419600         ; Expire
                         604600 )       ; Negative Cache TTL

; name servers - NS records
    IN  NS  ldap.local.

; name servers - A records
ldap.local.          IN      A

   ' > /etc/bind/db.local2

   # Let us add to /etc/hosts just in case
   echo " ldap.local" > /etc/hosts

   # lets make sure bind starts at bootup
    systemctl enable named.service
   #Now test it
nslookup ldap.local

   # Lets add DNS to any ethernet ports. 

for i in `ifconfig | egrep ^[a-z] | cut -d ":" -f1 | grep -v "^lo"`; do
  systemd-resolve --interface $i --set-dns

   # Now check name resolution
   systemd-resolve --status
   # You should see as the DNS for all ethernet ports. 

   # Check is DNS is running right.
   nslookup ldap.local
   nslookup google.com

The test should look like

root@linux4:/home/mark# nslookup ldap.local

Non-authoritative answer:
Name:	ldap.local

root@linux4:/home/mark# nslookup google.com

Non-authoritative answer:
Name:	google.com
Name:	google.com
Address: 2607:f8b0:4025:815::200e

  1. Is ldap.local is working, but google.com is not, then there is something wrong with the forwarding.
  2. If google.com is working, and ldap.local is not, it is not hitting the local server for DNS lookups or DNS configuration is wrong.

Now, you might have to create a script at start.

Reboot your system, hopefully named comes up and DNS works!