Setup DNS server
Setup master&slave DNS servers on Rocky 8.4
Servers:
- Master DNS server
- Slave DNS server
- Client
Preparation
1. yum update
2. enable dmesg logging
create /etc/systemd/system/dmesg.service
touch /var/log/dmesg and verify SELinux contexts
enable dmesg
3. enable syslog/messages
Setup Master DNS server
2. install bind packages
3. enable and start dns service
5. create zone files
edit forward.homelab file
edit reverse.homelab file
6. restart named
7. permit tcp&udp port 53 in firewall
8. check bind config
edit /etc/NetworkManager/NetworkManager.conf, append dns=none in main section
edit /etc/resolv.conf to point nameserver to master DNS server IP
restart network manager
2. test dns server on the client
Setup Slave DNS server
2. install bind packages
3. edit bind configuration /etc/named.conf
4. enable and start bind service
check zone files are replicated from the master
5. permit tcp&udp port 53 in firewall
edit /etc/resolv.conf to add slave DNS server IP
use recurse or no recurse in nslookup command
reverse lookup
Caching and forwarding mode
edit /etc/named.conf, add "forwarders" option and enable recursion.
Set alias (CNAME)
edit /var/named/forward.homelab, add alias
Tcpdump DNS query
Recursion "yes" on master DNS server
Client sents dns query with "recursion" flag, tell DNS server to do query recursively.

Master DNS server return answer and also tell client that the server can do query recursively.

Recursion "no" on master and slave.
Client sents query with "recursion" flag, tell DNS server to do query recursively.

Master DNS server returns answer and tell client that the server can't do recursive queries.

Client sent query with "recursion" flag to the slave DNS server. (because both master and slave are configured in /etc/resolv.conf, noslookup tries next nameserver)

Slave DNS server returns answer and tell client that the server can't do recursive queries.

KB
recursion
If yes, and a DNS query requests recursion, then the server attempts to do all the work required to answer the query. If recursion is off and the server does not already know the answer, it returns a referral response. The default is yes. Note that setting recursion no does not prevent clients from getting data from the server’s cache; it only prevents new data from being cached as an effect of client queries. Caching may still occur as an effect of the server’s internal operation, such as NOTIFY address lookups.
zone file syntax
- Comments start with a semicolon ";" and go to the end of line.
- Empty lines are allowed; any combination of tabs and spaces acts as a delimiter.
- RR are defined line by line as :
[Name] [TTL] [CLASS] TYPE RDATA
- if no Name, the name is taken from the last stated RR
- if Name exists, it starts at the first character of the line
- if Name is not dot-terminated (non FQDN), the default domain name defined by $ORIGIN directives is concatenated to Name
- if no TTL, the TTL is defined by $TTL directives.
- if no CLASS, the CLASS is taken from the last stated RR
- TTL and CLASS can be exchanged.
- $TTL integer_value sets the default value of TTL for following RRs in file (RFC2308, bind>8.1)
- $ORIGIN fqdn_name sets the default value of domain name for following RRs in file. Initially, in BIND, the value is set to the current zone name.
- $INCLUDE filename inserts the named file into the current file. NB: be careful about value of $TTL or $ORIGIN after a $INCLUDE
- "@" is used to denote the current default domain name.
- "(" and ")" are used to group data that crosses a line boundary. Line terminations are not recognized within parentheses
- "" is used to quote special characters. Ex : "." can be used to place a dot character in a label; "\223" is the 8-bit character corresponding to decimal value 223.
stylistic hints
- Organize RR : Start with SOA, NS and MX of the zone, continue with delegation (NS) and glue. Group RR by names.
- Comments are useful
- Use spaces or tabulations for vertical alignment
- Start file with a $ORIGIN and a $TTL
- Try to avoid writing of the zone name in the file
- Generate serial number in SOA as : year/month/day/version 4+2+2+2.
- BE CAREFUL: Modify the serial number each time the master file is modified
dig command query with tcp
for centos 8, update yum repos mirror
Reference
https://www.linuxteck.com/how-to-install-and-configure-master-slave-dns-in-centos-rhel-7-6/
http://www-inf.int-evry.fr/~hennequi/CoursDNS/NOTES-COURS_eng/syntax.html
https://techglimpse.com/failed-metadata-repo-appstream-centos-8/
https://bind9.readthedocs.io/en/v9_16_6/reference.html
https://medium.com/liveonnetwork/need-a-refresher-on-dns-concepts-4dcdfda6365d