Overview
This lecture introduces DNSMasq, a lightweight program that provides DNS and other networking services, and covers its installation, configuration, and usage as a caching and authoritative DNS server.
DNSMasq Introduction and Installation
- DNSMasq is a centralized tool offering DNS, DHCP, TFTP, and PXE services, suitable for small to medium setups.
- Install DNSMasq using
sudo apt install dnsmask on your machine.
- After installation, DNSMasq provides basic DNS caching functionality by default.
Using DNSMasq as a Caching DNS Server
- DNSMasq caches DNS queries, reducing repeated external lookups.
- Use
dig www.example.com @localhost to test DNSMasq's response.
- Running DNSMasq in debug mode (
sudo dnsmask -d -q) shows detailed information and logs queries.
Debugging and Monitoring DNS Queries
- Stop the default DNSMasq service with
sudo service dnsmask stop before starting debug mode.
- The
-d flag runs DNSMasq in debug; -q enables query logging.
- In debug mode, you see the flow: receiving, forwarding, and replying to DNS queries, including cache responses.
Configuring DNSMasq as an Authoritative DNS Server
- DNSMasq can serve authoritative DNS answers for a custom list of hostnames and IP addresses.
- Create a hosts file (similar to
/etc/hosts) mapping IPs to hostnames.
- Start DNSMasq with the
-h flag to load the custom host file (sudo dnsmask -d -q -h myhosts).
- When queried for these hostnames, DNSMasq provides direct (authoritative) responses.
Handling Unknown Hostnames
- If a queried hostname is not in the hosts file, DNSMasq forwards the query to the next configured DNS server.
- If no external server can resolve the query, the response is
NXDOMAIN (nonexistent domain).
Key Terms & Definitions
- DNSMasq — A lightweight service providing DNS, DHCP, TFTP, and PXE functionality.
- Caching DNS Server — Stores DNS query results to speed up repeated lookups.
- Authoritative DNS Server — Directly provides the definitive IP address for specific hostnames.
- NXDOMAIN — DNS response indicating the requested domain does not exist.
Action Items / Next Steps
- Practice installing DNSMasq and running it in debug mode.
- Create and use a custom hosts file with DNSMasq.
- Experiment with queries for both known and unknown hostnames.