269 words
1 minutes
DNS (Domain Name System)

DNS (Domain Name System)#

πŸ“ What is DNS?#

  • DNS translates domain names (e.g., www.hackthebox.com) into IP addresses.
  • It’s like the Internet’s phonebook, helping browsers find websites.
  • DNS is distributed β€” no central database.
  • Thousands of DNS servers globally share this data.

🌐 Types of DNS Servers#

TypeRole
DNS Root ServerTop-level; connects TLDs (e.g., .com, .org) with authoritative servers. 13 exist globally, managed by ICANN.
Authoritative NameserverFinal authority for a DNS zone (e.g., domain.com). Responds with official DNS data.
Non-authoritative NameserverNot the main source. Gets info from others via recursive/iterative querying.
Caching ServerTemporarily stores DNS responses to reduce load and speed up queries.
Forwarding ServerForwards queries to another DNS server.
ResolverOften on your PC/router; starts the resolution process. Not authoritative.

πŸ” DNS Security#

  • DNS is not encrypted by default.
  • Vulnerable to spying, spoofing, MITM attacks.
  • Secure alternatives:
    • DoT (DNS over TLS)
    • DoH (DNS over HTTPS)
    • DNSCrypt (Encrypts DNS traffic)

πŸ—‚οΈ DNS Records#

RecordFunction
AIPv4 address
AAAAIPv6 address
MXMail servers
NSName servers
TXTMisc info (SPF, DMARC, Google verification)
CNAMEAlias for another domain
PTRReverse DNS β€” IP to domain
SOAZone info + admin email (hostmaster@domain.com)

πŸ§ͺ Example:

dig soa www.inlanefreight.com

βš™οΈ DNS Configuration (Bind9 Example)#

1. Local Config Files (Main Control)#

  • /etc/bind/named.conf.local
  • /etc/bind/named.conf.options
  • /etc/bind/named.conf.log

πŸ“Œ Example:

zone "domain.com" {
  type master;
  file "/etc/bind/db.domain.com";
  allow-update { key rndc-key; };
};

2. Zone Files (Forward Lookup)#

πŸ“Œ Example: /etc/bind/db.domain.com

$ORIGIN domain.com
@ IN SOA dns1.domain.com. hostmaster.domain.com. (
  2001062501 ; serial
  21600 ; refresh
  3600 ; retry
  604800 ; expire
  86400 ) ; minimum TTL
IN NS ns1.domain.com.
IN MX 10 mx.domain.com.
server1 IN A 10.129.14.5
www IN CNAME server2

3. Reverse Zone Files#

πŸ“Œ Example: /etc/bind/db.10.129.14

$ORIGIN 14.129.10.in-addr.arpa
@ IN SOA dns1.domain.com. hostmaster.domain.com. (
  2001062501 ; serial
  ...
)
5 IN PTR server1.domain.com.

⚠️ Dangerous Configurations (Security Risks)#

OptionDescription
allow-queryControls who can query the DNS server
allow-recursionControls who can use recursive lookups

Misconfigurations (especially with Bind9) can:

  • Leak data
  • Allow DNS amplification attacks
  • Create backdoors for attackers