Why DNS?
People use names (www.example.com); packets need addresses (198.51.100.10). The Domain Name System translates. A PC asks its DNS server over UDP port 53 (TCP 53 for big answers and zone transfers), and the server answers or asks other servers for it.
Record types
| Type | Holds | Example |
|---|---|---|
| A | An IPv4 address | www.example.com → 198.51.100.10 |
| AAAA | An IPv6 address | www.example.com → 2001:db8:100::10 |
| CNAME | An alias for another name | web.example.com → www.example.com |
| MX | The mail server for a domain, with a preference | example.com → 10 mail.example.com |
| NS | A name server for the domain | example.com → ns1.example.com |
| PTR | Reverse: an address to a name | 50.1.1.10.in-addr.arpa → ns1.example.com |
| TXT | Free text (used for mail security, verification) | "v=spf1 mx -all" |
| SOA | Start of authority: who runs the zone, timers |
PCs get their DNS server from DHCP (or it's set by hand). nslookup (every OS) and dig (Linux, macOS) ask questions directly:
In NetLab
▶ PC1 NetLab Windows-style command prompt. Type help to see the commands. C:\Users\student>nslookup www.example.com Server: ns1.example.com Address: 10.1.1.50 Non-authoritative answer: Name: www.example.com Address: 198.51.100.10 C:\Users\student>nslookup web.example.com Server: ns1.example.com Address: 10.1.1.50 Non-authoritative answer: Name: www.example.com Address: 198.51.100.10 Aliases: web.example.com C:\Users\student>nslookup -type=mx example.com Server: ns1.example.com Address: 10.1.1.50 Non-authoritative answer: example.com MX preference = 10, mail exchanger = mail.example.com C:\Users\student>nslookup nowhere.example.com Server: ns1.example.com Address: 10.1.1.50 *** ns1.example.com can't find nowhere.example.com: Non-existent domain C:\Users\student>ping www.example.com Pinging www.example.com [198.51.100.10] with 32 bytes of data: Request timed out. Request timed out. Reply from 198.51.100.10: bytes=32 time<1ms TTL=62 Reply from 198.51.100.10: bytes=32 time<1ms TTL=62 Ping statistics for 198.51.100.10: Packets: Sent = 4, Received = 2, Lost = 2 (50% loss), Approximate round trip times in milli-seconds: Minimum = 0ms, Maximum = 0ms, Average = 0ms ▶ PC2 student@PC2:~$ dig www.example.com +short 198.51.100.10 student@PC2:~$ dig example.com txt ; <<>> DiG 9.18.18 <<>> example.com txt ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 4019 ;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 1 ;; QUESTION SECTION: ;example.com. IN TXT ;; ANSWER SECTION: example.com. 300 IN TXT "v=spf1 mx -all" ;; Query time: 1 msec ;; SERVER: 10.1.1.50#53(10.1.1.50) (UDP) ;; MSG SIZE rcvd: 56
DNS on a router
| Command | Does |
|---|---|
ip domain-lookup | Use DNS for names (on by default; labs often turn it off so typos don't hang the console) |
ip name-server 10.1.1.50 | The DNS server(s) to ask |
ip domain name example.com | Added to short names (and needed for SSH keys) |
ip host nms 10.1.1.50 | A static name, no DNS needed |
In NetLab
▶ R1 R1>enable R1#configure terminal Enter configuration commands, one per line. End with CNTL/Z. R1(config)#ip domain-lookup R1(config)#ip name-server 10.1.1.50 R1(config)#ip domain name example.com R1(config)#ip host core 10.0.12.2 R1(config)#end *Mar 1 00:00:07.000: %SYS-5-CONFIG_I: Configured from console by console R1#ping www Translating "www"...domain server (10.1.1.50) [OK] Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 198.51.100.10, timeout is 2 seconds: ..!!! Success rate is 60 percent (3/5), round-trip min/avg/max = 1/1/1 ms R1#ping core Type escape sequence to abort. Sending 5, 100-byte ICMP Echos to 10.0.12.2, timeout is 2 seconds: !!!!! Success rate is 100 percent (5/5), round-trip min/avg/max = 1/1/1 ms R1#show hosts Name lookup view: Global Default domain is example.com Name/address lookup uses domain service Name servers are 10.1.1.50 Codes: UN - unknown, EX - expired, OK - OK, ?? - revalidate temp - temporary, perm - permanent NA - Not Applicable None - Not defined Host Port Flags Age Type Address(es) core None (perm, OK) 0 IP 10.0.12.2
Remember: A, AAAA, CNAME, MX, NS, PTR, TXT. DNS uses UDP (and TCP) port 53.