Bind9 (DNS) Installation 24.04LTS: Difference between revisions

From ScottWiki
Jump to navigation Jump to search
 
(16 intermediate revisions by 2 users not shown)
Line 36: Line 36:


<pre>
<pre>
acl "scottworld-lan" {
include "/etc/bind/rndc.key";
        localnets;
        10.3.0.0/16;
};


zone "scottworld.net" {
zone "scottworld.net" {
Line 45: Line 42:
         file "/var/lib/bind/zones/db.scottworld.net";
         file "/var/lib/bind/zones/db.scottworld.net";
         check-names ignore;
         check-names ignore;
         allow-update { scottworld-lan; };
         allow-update { key rndc-key; };
       
};
};


Line 52: Line 50:
         file "/var/lib/bind/zones/db.10.3";
         file "/var/lib/bind/zones/db.10.3";
         check-names ignore;
         check-names ignore;
         allow-update { scottworld-lan; };
         allow-update { key rndc-key; };
};
};
</pre>
</pre>
Line 81: Line 79:
                         A      10.3.200.1
                         A      10.3.200.1
$ORIGIN scottworld.net.
$ORIGIN scottworld.net.
asteroid               A      10.3.101.2
amazon-5f60112a9        A      10.3.50.13
backcam                 A      10.3.50.31
amazon-c01e642c8        A      10.3.50.12
$TTL 3600      ; 1 hour
asteriod               A      10.3.101.2
BOONBOX                A      10.3.100.3
BackCam                 A      10.3.50.31
                        DHCID  ( AAEBUghHomWwx+ZARvqg4ZdLpKhPOPgpW1kz/5rUBZVV
Chromecast              A      10.3.50.14
                                mB8= ) ; 1 1 32
$TTL 604800    ; 1 week
comet                  A      10.3.200.3
comet                  A      10.3.200.3
cyd                    A      10.3.50.24
cyd                    A      10.3.50.24
ddhomerun              A      10.3.50.1
ddhomerun              A      10.3.50.1
$TTL 3600      ; 1 hour
Dining-main             A      10.3.50.5
DESKTOP-Q3C0NFT        A      10.3.100.37
Dining-uplighter1       A      10.3.50.17
                        DHCID  ( AAEB61rcJVQOhiz+yeEwQOHXAznDG8ZCwXkyxMdAyUJR
Dining-uplighter2       A      10.3.50.18
                                tSY= ) ; 1 1 32
DoorBell               A      10.3.50.32
$TTL 604800    ; 1 week
Dining-Main             A      10.3.50.5
Dining-Uplighter1       A      10.3.50.22
Dining-Uplighter2       A      10.3.50.18
doorbell               A      10.3.50.32
envoy                  A      10.3.50.2
envoy                  A      10.3.50.2
$TTL 3600      ; 1 hour
FrontCam               A      10.3.50.30
esp32-E35268            A      10.3.100.97
                        DHCID  ( AAEBxPfgRxFRi+N12m5RY648gCiQabwBlRTHFI4iINRJ
                                Uro= ) ; 1 1 32
$TTL 604800    ; 1 week
ESP_B8019D              A      10.3.50.6
frontcam               A      10.3.50.30
gateway                A      10.3.1.1
gateway                A      10.3.1.1
$TTL 1200       ; 20 minutes
HotWaterRelay          A       10.3.50.33
jupiter                 A      10.3.100.37
ipPhone                 A      10.3.50.40
$TTL 604800    ; 1 week
Landing-main           A      10.3.50.10
Landing-Main           A      10.3.50.10
Lounge-colin           A      10.3.50.21
Lounge-Colin           A      10.3.50.21
Lounge-floor           A      10.3.50.16
Lounge-Floor           A      10.3.50.16
Lounge-larry           A      10.3.50.15
Lounge-Larry           A      10.3.50.15
Lounge-main             A      10.3.50.4
Lounge-Main             A      10.3.50.4
mame                   A      10.3.50.20
Mame                   A      10.3.50.20
mars                    A      10.3.200.2
mars                    A      10.3.200.2
$TTL 1200      ; 20 minutes
mimas                  A      10.3.101.3
mimas                  A      10.3.101.3
$TTL 604800    ; 1 week
MiniR2                  A      10.3.50.23
mqtt                    CNAME  mars
mqtt                    CNAME  mars
$TTL 1200      ; 20 minutes
Neptune                A      10.3.100.13
$TTL 604800    ; 1 week
patio                  A      10.3.50.6
patio                  A      10.3.50.6
$TTL 1200      ; 20 minutes
phobos                  A      10.3.100.148
$TTL 604800    ; 1 week
porch                  A      10.3.50.7
porch                  A      10.3.50.7
PowerCord1              A      10.3.50.19
PowerCord              A      10.3.50.19
printer                A      10.3.101.100
printer                A      10.3.101.100
$TTL 3600      ; 1 hour
$TTL 604800    ; 1 week
roku                    A      10.3.50.9
roku                    A      10.3.50.9
$TTL 1200      ; 20 minutes
saturn                  A      10.3.101.1
saturn                  A      10.3.100.12
scottcloud              CNAME  solaris
$TTL 604800    ; 1 week
scottcloud              A      10.3.200.1
scotthome              CNAME  solaris
scotthome              CNAME  solaris
$TTL 3600      ; 1 hour
scottscreen            A      10.3.50.3
scottscreen            A      10.3.50.3
$TTL 3600      ; 1 hour
$TTL 604800    ; 1 week
solaris                A      10.3.200.1
solaris                A      10.3.200.1
titan                  A      10.3.100.21
WAPLoft                A      10.3.1.2
$TTL 604800    ; 1 week
WAPLounge              A      10.3.1.3
wiki                    CNAME  scottworrs.cluster020.hosting.ovh.net.
wiki                    CNAME  scottworrs.cluster020.hosting.ovh.net.
wikimin                CNAME  solaris
wikimin                CNAME  solaris
www                    CNAME  scottworrs.cluster020.hosting.ovh.net.
www                    CNAME  scottworrs.cluster020.hosting.ovh.net.
yamaha                  A      10.3.50.8
yamaha                  A      10.3.50.8
</pre>
</pre>


Line 163: Line 134:
$TTL 604800    ; 1 week
$TTL 604800    ; 1 week
3.10.in-addr.arpa      IN SOA  solaris.scottworld.net. mark\@scottworld.net. (
3.10.in-addr.arpa      IN SOA  solaris.scottworld.net. mark\@scottworld.net. (
                                 1123      ; serial
                                 1          ; serial
                                 604800    ; refresh (1 week)
                                 604800    ; refresh (1 week)
                                 86400      ; retry (1 day)
                                 86400      ; retry (1 day)
Line 169: Line 140:
                                 604800    ; minimum (1 week)
                                 604800    ; minimum (1 week)
                                 )
                                 )
                         NS      solaris.
                         NS      solaris.scottworld.net.
$ORIGIN 1.3.10.in-addr.arpa.
$ORIGIN 1.3.10.in-addr.arpa.
$TTL 3600      ; 1 hour
1                      PTR    gateway.scottworld.net.
1                      PTR    gateway.scottworld.net.
2                      PTR    WAPLoft.scottworld.net.
3                      PTR    WAPLounge.scottworld.net.
$ORIGIN 50.3.10.in-addr.arpa.
1                      PTR    ddhomerun.scottworld.net.
10                      PTR    Landing-main.scottworld.net.
12                      PTR    amazon-c01e642c8.scottworld.net.
13                      PTR    amazon-5f60112a9.scottworld.net.
14                      PTR    Chromecast.scottworld.net.
15                      PTR    Lounge-larry.scottworld.net.
16                      PTR    Lounge-floor.scottworld.net.
17                      PTR    Dining-uplighter1.scottworld.net.
18                      PTR    Dining-uplighter2.scottworld.net.
19                      PTR    PowerCord1.scottworld.net.
2                      PTR    envoy.scottworld.net.
20                      PTR    mame.scottworld.net.
21                      PTR    Lounge-colin.scottworld.net.
23                      PTR    MiniR2.scottworld.net.
24                      PTR    cyd.scottworld.net.
3                      PTR    scottscreen.scottworld.net.
30                      PTR    FrontCam.scottworld.net.
31                      PTR    BackCam.scottworld.net.
32                      PTR    DoorBell.scottworld.net.
33                      PTR    HotWaterRelay.scottworld.net.
4                      PTR    Lounge-main.scottworld.net.
40                      PTR    ipPhone.scottworld.net.
5                      PTR    Dining-main.scottworld.net.
6                      PTR    patio.scottworld.net.
7                      PTR    porch.scottworld.net.
8                      PTR    yamaha.scottworld.net.
9                      PTR    roku.scottworld.net.
$ORIGIN 100.3.10.in-addr.arpa.
$ORIGIN 101.3.10.in-addr.arpa.
1                      PTR    saturn.scottworld.net.
100                    PTR    printer.scottworld.net.
2                      PTR    asteroid.scottworld.net.
3                      PTR    mimas.scottworld.net.
$ORIGIN 200.3.10.in-addr.arpa.
$ORIGIN 200.3.10.in-addr.arpa.
$TTL 36000      ; 10 hours
1                      PTR    solaris.scottworld.net.
1                      PTR    solaris.scottworld.net.
2                      PTR    mars.scottworld.net.
2                      PTR    mars.scottworld.net.
Line 187: Line 196:
  nano named.conf.options
  nano named.conf.options


add this line to the options file.
add these lines to the options file.


  allow-query-cache { localnets; 10.3.0.0/24; };
  allow-query-cache { localnets; 10.3.0.0/16; };
allow-recursion { localnets; 10.3.0.0/16; };


== Set folder permissions and test ==  
== Set folder permissions and test ==  
Line 196: Line 206:
Set the permissions on the folder / zone files so BIND can write to them.
Set the permissions on the folder / zone files so BIND can write to them.


  chown bind:bind /var/lib/bind/zones
  chown bind:bind /var/lib/bind/zones -R
  chmod 770 /var/lib/bind/zones -R
  chmod 770 /var/lib/bind/zones
chmod 660 /var/lib/bind/zones/*


Restart BIND and DHCP to use the new settings:
Restart BIND


  service bind9 restart
  systemctl start bind9.service
service isc-dhcp-server restart




Line 208: Line 218:
Test that the dns lookups works with the local server:
Test that the dns lookups works with the local server:


  dig google.com
  dig @10.3.200.1 google.com


The response should be:
The response should be:
Line 243: Line 253:
</pre>
</pre>


Test that all of your computers are listed with the following command:
host -l scottworld.net
The output should list all of your entered hosts:
Example:
<pre>
scottworld.net name server solaris.scottworld.net.
scottworld.net has address 192.168.3.200
scottworld.net has IPv6 address ::1
adwebmail.scottworld.net has address 213.171.195.75
android_832db9ab2532e69b.scottworld.net has address 192.168.3.11
Brians-iPhone-2.scottworld.net has address 192.168.3.48
jupiter.scottworld.net has address 192.168.3.15
Keiths-iPhone.scottworld.net has address 192.168.3.47
mail.scottworld.net has address 213.171.216.114
mythboxBED.scottworld.net has address 192.168.3.16
mythboxtv.scottworld.net has address 192.168.3.49
ns.scottworld.net has address 192.168.3.200
PRINTER.scottworld.net has address 192.168.3.44
smtp.scottworld.net has address 213.171.216.50
solaris.scottworld.net has address 192.168.3.200
solaris2.scottworld.net has address 192.168.3.201
venus.scottworld.net has address 192.168.3.14
webmail.scottworld.net has address 213.171.216.114
www.scottworld.net has address 88.208.252.199
ye12744LT.scottworld.net has address 192.168.3.46
</pre>


Test that the reverse lookup works:
Test that the reverse lookup works:
Line 292: Line 274:
  rndc thaw <zone you want to unfreeze>
  rndc thaw <zone you want to unfreeze>


== Update Netplan to use yourself as DNS ==
nano /etc/netplan/00-solaris.yaml


Save and close the editor when you are finished.  
Change the nameserver to yourself 10.3.200.1
Reload the systemd daemon to read the new configuration into the running system:


  sudo systemctl daemon-reload
  netplan apply
sudo systemctl restart bind9

Latest revision as of 01:17, 20 March 2024

This will configure split DNS. This will allow you to create a local DNS zone "scottworld.net" which will handle all local requests. It will be an extension of scottworld.net which is the registered domain. Requests for scottworld.net hosts (and other traffic) that are not local are forwarded out to the internet.

Install bind.

apt install bind9

Shut down the service for configuration

systemctl stop bind9.service

Update bind to use IP 4 addresses only

This will prevent a whole bunch of IP6 fails and your log filling up.

nano /etc/default/named
#
# run resolvconf?
RESOLVCONF=no

# startup options for the server
OPTIONS="-u bind -4"


Define the zones for the local domain:

We will now edit named.conf.local and set up the zones we are using for DNS.

sudo nano /etc/bind/named.conf.local

Add a zones and their location for the local domain and the access rights. Here we define 2 zones, a forward and reverse zone.

include "/etc/bind/rndc.key";

zone "scottworld.net" {
        type master;
        file "/var/lib/bind/zones/db.scottworld.net";
        check-names ignore;
        allow-update { key rndc-key; };
        
};

zone "3.10.in-addr.arpa" {
        type master;
        file "/var/lib/bind/zones/db.10.3";
        check-names ignore;
        allow-update { key rndc-key; };
};

Set up a Zones Folder

Create a zone folder to host the zone files in /var/lib/bind/

mkdir /var/lib/bind/zones

Configure the local forward lookup zone

nano /var/lib/bind/zones/db.scottworld.net

Here we also add to STATIC hosts as A records (contained in the zone file)

$ORIGIN .
$TTL 604800     ; 1 week
scottworld.net          IN SOA  solaris.scottworld.net. mark.scottworld.net. (
                                1          ; serial
                                604800     ; refresh (1 week)
                                86400      ; retry (1 day)
                                2419200    ; expire (4 weeks)
                                604800     ; minimum (1 week)
                                )
                        NS      solaris.scottworld.net.
                        A       10.3.200.1
$ORIGIN scottworld.net.
amazon-5f60112a9        A       10.3.50.13
amazon-c01e642c8        A       10.3.50.12
asteriod                A       10.3.101.2
BackCam                 A       10.3.50.31
Chromecast              A       10.3.50.14
comet                   A       10.3.200.3
cyd                     A       10.3.50.24
ddhomerun               A       10.3.50.1
Dining-main             A       10.3.50.5
Dining-uplighter1       A       10.3.50.17
Dining-uplighter2       A       10.3.50.18
DoorBell                A       10.3.50.32
envoy                   A       10.3.50.2
FrontCam                A       10.3.50.30
gateway                 A       10.3.1.1
HotWaterRelay           A       10.3.50.33
ipPhone                 A       10.3.50.40
Landing-main            A       10.3.50.10
Lounge-colin            A       10.3.50.21
Lounge-floor            A       10.3.50.16
Lounge-larry            A       10.3.50.15
Lounge-main             A       10.3.50.4
mame                    A       10.3.50.20
mars                    A       10.3.200.2
mimas                   A       10.3.101.3
MiniR2                  A       10.3.50.23
mqtt                    CNAME   mars
patio                   A       10.3.50.6
porch                   A       10.3.50.7
PowerCord               A       10.3.50.19
printer                 A       10.3.101.100
roku                    A       10.3.50.9
saturn                  A       10.3.101.1
scottcloud              CNAME   solaris
scotthome               CNAME   solaris
scottscreen             A       10.3.50.3
solaris                 A       10.3.200.1
WAPLoft                 A       10.3.1.2
WAPLounge               A       10.3.1.3
wiki                    CNAME   scottworrs.cluster020.hosting.ovh.net.
wikimin                 CNAME   solaris
www                     CNAME   scottworrs.cluster020.hosting.ovh.net.
yamaha                  A       10.3.50.8

Configure the local reverse lookup zone

nano /var/lib/bind/zones/db.10.3

$ORIGIN .
$TTL 604800     ; 1 week
3.10.in-addr.arpa       IN SOA  solaris.scottworld.net. mark\@scottworld.net. (
                                1          ; serial
                                604800     ; refresh (1 week)
                                86400      ; retry (1 day)
                                2419200    ; expire (4 weeks)
                                604800     ; minimum (1 week)
                                )
                        NS      solaris.scottworld.net.
$ORIGIN 1.3.10.in-addr.arpa.
1                       PTR     gateway.scottworld.net.
2                       PTR     WAPLoft.scottworld.net.
3                       PTR     WAPLounge.scottworld.net.

$ORIGIN 50.3.10.in-addr.arpa.
1                       PTR     ddhomerun.scottworld.net.
10                      PTR     Landing-main.scottworld.net.
12                      PTR     amazon-c01e642c8.scottworld.net.
13                      PTR     amazon-5f60112a9.scottworld.net.
14                      PTR     Chromecast.scottworld.net.
15                      PTR     Lounge-larry.scottworld.net.
16                      PTR     Lounge-floor.scottworld.net.
17                      PTR     Dining-uplighter1.scottworld.net.
18                      PTR     Dining-uplighter2.scottworld.net.
19                      PTR     PowerCord1.scottworld.net.
2                       PTR     envoy.scottworld.net.
20                      PTR     mame.scottworld.net.
21                      PTR     Lounge-colin.scottworld.net.
23                      PTR     MiniR2.scottworld.net.
24                      PTR     cyd.scottworld.net.
3                       PTR     scottscreen.scottworld.net.
30                      PTR     FrontCam.scottworld.net.
31                      PTR     BackCam.scottworld.net.
32                      PTR     DoorBell.scottworld.net.
33                      PTR     HotWaterRelay.scottworld.net.
4                       PTR     Lounge-main.scottworld.net.
40                      PTR     ipPhone.scottworld.net.
5                       PTR     Dining-main.scottworld.net.
6                       PTR     patio.scottworld.net.
7                       PTR     porch.scottworld.net.
8                       PTR     yamaha.scottworld.net.
9                       PTR     roku.scottworld.net.

$ORIGIN 100.3.10.in-addr.arpa.

$ORIGIN 101.3.10.in-addr.arpa.
1                       PTR     saturn.scottworld.net.
100                     PTR     printer.scottworld.net.
2                       PTR     asteroid.scottworld.net.
3                       PTR     mimas.scottworld.net.

$ORIGIN 200.3.10.in-addr.arpa.
1                       PTR     solaris.scottworld.net.
2                       PTR     mars.scottworld.net.
3                       PTR     comet.scottworld.net.

; also list other computers

Allow the openVPN network to used locally cached DNS entries

nano named.conf.options

add these lines to the options file.

allow-query-cache { localnets; 10.3.0.0/16; };
allow-recursion { localnets; 10.3.0.0/16; };

Set folder permissions and test

Set the permissions on the folder / zone files so BIND can write to them.

chown bind:bind /var/lib/bind/zones -R
chmod 770 /var/lib/bind/zones
chmod 660 /var/lib/bind/zones/*

Restart BIND

systemctl start bind9.service


Test that the dns lookups works with the local server:

dig @10.3.200.1 google.com

The response should be:

root@solaris:~# dig google.com

; <<>> DiG 9.8.1-P1 <<>> google.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 36080
;; flags: qr rd ra; QUERY: 1, ANSWER: 11, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;google.com.                    IN      A

;; ANSWER SECTION:
google.com.             32      IN      A       173.194.34.69
google.com.             32      IN      A       173.194.34.65
google.com.             32      IN      A       173.194.34.71
google.com.             32      IN      A       173.194.34.70
google.com.             32      IN      A       173.194.34.73
google.com.             32      IN      A       173.194.34.78
google.com.             32      IN      A       173.194.34.66
google.com.             32      IN      A       173.194.34.68
google.com.             32      IN      A       173.194.34.67
google.com.             32      IN      A       173.194.34.64
google.com.             32      IN      A       173.194.34.72

;; Query time: 1412 msec
;; SERVER: 192.168.3.1#53(192.168.3.1)
;; WHEN: Mon Apr 30 10:15:47 2012
;; MSG SIZE  rcvd: 204


Test that the reverse lookup works:

host 10.3.200.1

Response:

root@solaris:/var/lib/bind/zones# host 10.3.200.1
1.200.3.10.in-addr.arpa domain name pointer solaris.
1.200.3.10.in-addr.arpa domain name pointer solaris.local.

REMEMBER Do not forget to update the serial every time you make any changes to a zone file.

To make a change to DNS.

rndc freeze <zone you want to freeze>
nano /var/lib/bind/zones/<file you want to change>
Make sure you update the serial number
rndc thaw <zone you want to unfreeze>

Update Netplan to use yourself as DNS

nano /etc/netplan/00-solaris.yaml

Change the nameserver to yourself 10.3.200.1

netplan apply