Install Bind9 DNS
Pull the BIND9 docker image before disabling built-in DNS server
docker pull ubuntu/bind9:latest
Disable Ubuntu built-in DNS resolver
- Stop the OS built-in DNS service
service systemd-resolved stop - Backup existing
/etc/resolv.confjust for safety.mv /etc/resolv.conf /etc/resolv.conf.backup - Disable the service from startup
systemctl disable systemd-resolved - Confirm if port 53 is free:
sudo lsof -i :53. this should return nothing.
Installation:
cd /epiclabs23/eh/eh-services/dns- Start docker container:
docker run -d \
--name bind9 \
-p 53:53/udp \
-p 53:53/tcp \
-e TZ=Asia/Dhaka \
-e BIND9_USER=root \
-v /epiclabs23/eh/eh-services/dns/etc/bind:/etc/bind \
-v /epiclabs23/eh/eh-services/dns/var/cache/bind:/var/cache/bind \
-v /epiclabs23/eh/eh-services/dns/var/lib/bind:/var/lib/bind \
--restart=always \
ubuntu/bind9:latest
- Configure Your Local Machine to Use the DNS Server:
vim /etc/resolv.confthen add following content
nameserver 127.0.0.1
nameserver 8.8.8.8
nameserver 45.125.222.158
search .
- Test DNS server:
dig @127.0.0.1 www.example.local
or
nslookup www.example.local 127.0.0.1
- Managing DNS server:
docker exec bind9 named-checkzone ehm23.com /etc/bind/zones/db.ehm23.com
docker exec bind9 named-checkzone 57.169.49.103.in-addr.arpa /etc/bind/zones/db.57.169.49.103
docker exec bind9 rndc reload
docker stop bind9
docker start bind9
docker logs bind9
- Settings, forward DNS etc are available in:
./etc/bind/named.conf.options
Adding a new zone file:
- Copy the
db.example.localfile as template, make changes accordingly. - For any subdomain add an 'A' entry on this very same file.
- Update
named.conf.localwith the new zone file.
Debug
Start built-in DNS: service systemd-resolved start
Check status of built-in DNS: service systemd-resolved status
Enable the built-in DSN in startup systemctl enable systemd-resolved
Copy back the backed up config file: cp /etc/resolv.conf.backup /etc/resolv.conf