- Start the command-line program
make run
- Look up a domain name
lookup x.x.x.x
(ex:lookup www.cs.ubc.ca
)
- Set the root name server (optional, default is 199.7.83.42 which is close to UBC!)
server x.x.x.x
(ex:server 8.8.8.9
)
- Set verbose tracing on (optional, to print a trace of all queries and responses)
trace on | off
- Print the contents of the DNS cache (optional)
dump
- Quit
quit
This program is an iterative DNS resolver, meaning that the client repeatedly makes requests to DNS servers to resolve a domain name to an IP address (The code contains a lot of comments). Here are two example lookups, which provide the corresponding dig commands for a live demo:
- We can simulate
lookup www.cs.ubc.ca
as follows:
dig +norecurse @199.7.83.42 www.cs.ubc.ca
dig +norecurse @185.159.196.2 www.cs.ubc.ca
dig +norecurse @137.82.1.1 www.cs.ubc.ca
dig +norecurse @137.82.61.120 www.cs.ubc.ca
→ we got the answer 142.103.6.5!
- We can simulate
lookup finance.google.ca
(which contains aliases) as follows:
dig +norecurse @199.7.83.42 finance.google.ca
dig +norecurse @185.159.196.2 finance.google.ca
dig +norecurse @199.7.83.42 ns3.google.com
→ we needed to lookup the IP of an authoritative nameserverdig +norecurse @192.33.14.30 ns3.google.com
→ we got the answer 216.239.36.10 for the authoritative nameserverdig +norecurse @216.239.36.10 finance.google.ca
→ we got the answer 142.251.33.110!
Reference: https://www.ietf.org/rfc/rfc1035.txt