DNS

A name is found by asking down a tree, then remembered

Laptopstub resolverwww.example.com?4 msRecursive resolverISP, office or 1.1.1.114 msRoot server (.)ask the .com servers: a.gtld-servers.netNS cached 6 days22 msTLD server (.com)ask example.com’s servers: ns1.example.comNS cached 2 days31 msAuthoritative (example.com)www.example.com is 203.0.113.80A record cached 300 sfirst lookup: 71 msnext lookup, from the resolver’s cache: 4 msA resolver walks from the root to the domain’s own servers, then caches each answer for its TTL.Your device asks one recursive resolver. That resolver asks a root server, which refers it to the .com servers, which refer it toexample.com’s authoritative servers, which give the answer. Every reply carries a time to live, so the next lookup withinthat time is answered from cache. That is why a DNS change can take up to the old TTL to reach everyone.

A recursive resolver asks the root, the TLD and the authoritative server: 71 ms the first time, 4 ms from cache until the TTL runs out.

DNS · Going deeper · 1 of 2

The record types and what each answers

$ORIGIN example.com.@     3600  IN SOA   ns1 admin 2026111501 ...@     86400 IN NS    ns1.example.com.@     3600  IN MX    10 mail.example.com.www   300   IN A     203.0.113.80www   300   IN AAAA  2001:db8::80shop  300   IN CNAME www.example.com.@     3600  IN TXT   "v=spf1 mx -all"_sip._tcp 3600 IN SRV 10 60 5060 sip80.113.0.203.in-addr.arpa. PTR www.example.com.start of authority: serial, timerswhich servers answer for the zonewhere mail for the domain goesname to IPv4 addressname to IPv6 addressalias to another namefree text: mail and ownership checksservice, port and hostaddress to name, in the reverse zoneEach record type answers one question about a name: address, alias, mail server, name server or reverse name.A and AAAA give addresses; CNAME points one name at another and cannot sit beside other records; MX lists mail servers with apreference (lower first); NS delegates the zone; PTR lives in the reverse zone for address-to-name lookups. The number after thename is the TTL in seconds. A zone transfer copies the zone between servers over TCP 53.

A and AAAA give addresses, CNAME an alias, MX the mail server, NS the name servers, PTR the name for an address.

DNS · Going deeper · 2 of 2

Private and genuine DNS: DoT, DoH and DNSSEC

MethodTransportProtectsDoes not protectPlain DNSUDP and TCP 53nothinganyone on the path can read or forgeDNS over TLS (DoT)TCP 853privacy on the pathanswers the resolver itself makes upDNS over HTTPS (DoH)TCP 443privacy, blends with web trafficthe same; also hides DNS from the firewallDNSSECsigned recordsanswers are genuineprivacy: queries are still readable$ dig www.example.com AAAA +short2001:db8::80$ nslookup -type=mx example.comexample.com   mail exchanger = 10 mail.example.com.Encrypting DNS keeps lookups private; DNSSEC proves answers are genuine. They solve different problems.DNSSEC adds signatures (RRSIG) checked against the zone’s key (DNSKEY), chained up to the root through DS records. DoT andDoH encrypt the conversation with the resolver. dig and nslookup query any record type; the hosts file is checked before DNS.

DoT (853) and DoH (443) encrypt lookups; DNSSEC signs records so forged answers fail.

DHCP

Four messages give a new device its address and settings

New laptopDHCP server1 Discover · 0.0.0.0:68 → 255.255.255.255:67broadcast: is there a server?2 Offer · 10.1.20.5:67 → 10.1.20.101you can have 10.1.20.101 for 1 day3 Request · 0.0.0.0:68 → 255.255.255.255:67broadcast: I take the offer from 10.1.20.54 Ack · 10.1.20.5:67 → 10.1.20.101confirmed, with gateway, DNS and leaseleasedrenew at 50%: 12 hrebind at 87.5%: 21 hexpires: 24 hA device with no address broadcasts for one; four messages, Discover, Offer, Request, Ack, lease it an address and settings.The client has no address yet, so it sends from 0.0.0.0 to the broadcast address. The lease brings the mask, default gateway andDNS servers too. At half the lease the client asks its server to renew; at 87.5% it asks any server. A client that hears nothinggives itself a 169.254.x.x link-local address, the sign that DHCP failed.

DHCP leases an address in four steps, DORA. A 24-hour lease renews at 12 hours; with no server, a client falls back to APIPA, 169.254.x.x.

DHCP · Going deeper

Relaying DHCP across a router

VLAN 20 · 10.1.20.0/24ClientClientRouterVlan20 10.1.20.1broadcastip helper-address 10.9.0.10on the client-facing interfaceunicast to 10.9.0.10, giaddr 10.1.20.1Server subnet 10.9.0.0/24DHCP serverpool for 10.1.20.0/24R1(config)# interface vlan 20R1(config-if)# ip helper-address 10.9.0.10R1# show ip dhcp binding        ! on a router acting as the serverA router stops broadcasts, so a relay turns the client’s broadcast into a unicast to a central DHCP server.The router writes its own interface address into the request’s gateway field (giaddr); the server uses it to pick the pool forthat subnet. One server can then serve every VLAN. Without the relay, clients in VLAN 20 end up with 169.254 addresses.

A DHCP relay (ip helper-address on the client-facing interface) forwards broadcasts as unicast with giaddr, so one server serves every subnet.

NAT and PAT

One public address shared by giving each connection its own port

Inside: private 192.168.1.0/24192.168.1.10:51514192.168.1.11:51514192.168.1.12:49200NAT routeroutside: 203.0.113.5Translation tableinsideoutside192.168.1.10:51514203.0.113.5:1024192.168.1.11:51514203.0.113.5:1025192.168.1.12:49200203.0.113.5:1026Web server198.51.100.7:443sees only203.0.113.5Port address translation lets a whole network share one public address by giving each connection its own port.Outgoing, the router rewrites the private source address and port to its public address and a free port, and records the pair.A reply to 203.0.113.5:1025 is matched in the table and sent back to 192.168.1.11:51514. The 16-bit port field allows about64,000 connections per public address and protocol. Nothing outside can start a connection in, which is why NAT feels like a firewall.

PAT (NAT overload) rewrites private source addresses and ports to one public address, tracking each pair in a translation table.

NAT and PAT · Going deeper

NAT terms, kinds and configuration

Term (Cisco)MeaningIn the exampleInside locala host’s real, private address192.168.1.10Inside globalthe public address it is seen as203.0.113.5Outside globalthe remote host’s real address198.51.100.7Outside localthe remote host as seen from inside198.51.100.7 (usually the same)interface gi0/0/0 ip nat insideinterface gi0/0/1 ip nat outsideaccess-list 1 permit 192.168.1.0 0.0.0.255ip nat inside source list 1 interface gi0/0/1 overloadStatic NATone private to one public, both ways: for a serverDynamic NATfrom a pool of public addresses, one per hostPAT (overload)many hosts share one address by port: the usualMark the inside and outside interfaces, say which hosts may be translated, and choose static, pool or overload.ip nat inside source static 192.168.1.20 203.0.113.20 publishes a server. show ip nat translations lists every pair.

Inside local is the private address, inside global the public one. Static NAT publishes a server; PAT with overload shares one address.

NTP

Four timestamps let every device agree on the time

Stratum 0 · GPS, atomic clockStratum 1 · server wired to itStratum 2 · core routersStratum 3 · switches, servers, PCsClient clockServer :123t1 = 1000t2 = 1130t3 = 1131t4 = 1021offset = ((t2 − t1) + (t3 − t4)) ÷ 2 = 120 msdelay = (t4 − t1) − (t3 − t2) = 20 msNTP stamps each request and reply, works out the clock offset and the network delay, and adjusts the clock.Here the client’s clock is 120 ms slow: four timestamps cancel out the 20 ms round trip. Accurate time matters for logsfrom many devices, certificates and Kerberos, which rejects clocks more than 5 minutes apart. NTP runs on UDP 123. NTS addsauthentication so a forged server cannot shift your clocks; PTP (IEEE 1588) reaches sub-microsecond accuracy with hardware help.

NTP (UDP 123) uses four timestamps to find the offset, 120 ms here, and the delay. Stratum counts the hops from the reference clock.

Ports

Every service has a port, and most have a secure twin

Plain textEncryptedTelnet23SSH22FTP20, 21SFTP22HTTP80HTTPS443LDAP389LDAPS636SMTP25SMTPS587SIP5060SIP over TLS5061Infrastructure and other servicesDNS53UDP, TCPDHCP67, 68UDPTFTP69UDPNTP123UDPSNMP161, 162UDPSMB445TCPSyslog514UDPSQL Server1433TCPRDP3389TCPEvery common service listens on a known port, and most plain-text protocols have an encrypted replacement.Firewall rules, captures and exam questions all speak in these numbers. SSH and SFTP share 22; HTTPS, DoH and QUIC share 443.Port 587 is mail submission with STARTTLS (465 is SMTP with TLS from the start); IMAPS is 993 and POP3S 995. FTP uses 21 forcommands and 20 for data in active mode. A service can run on any port: these are defaults, not guarantees.

Know the well-known ports: SSH 22, DNS 53, DHCP 67/68, HTTP 80, NTP 123, SNMP 161/162, LDAPS 636, RDP 3389, and each plain-text protocol’s encrypted replacement.

Ports · Going deeper

How an email travels

Sender’s appSender’s mail serverRecipient’s MXRecipient’s appTCP 587 + TLSsubmitTCP 25relay after an MX lookupIMAPS 993 or POP3S 995readDNS: example.org MX 10 mx1.example.orgSPF, DKIM and DMARC records in TXTMail is submitted on 587, relayed between servers on 25 after an MX lookup, and read with IMAP or POP.SMTP only sends. The sender’s server finds the recipient’s server through the MX record and hands the message over on port 25.The recipient reads it with IMAP, which keeps mail on the server, or POP3, which downloads it. TXT records (SPF, DKIM, DMARC)let receiving servers check that a message really comes from the domain it claims.

Mail is submitted on 587, relayed on 25 to the domain’s MX server, and read over IMAP (993) or POP3 (995).

Device management

Manage devices only over encrypted channels

What a capture showsTelnet, TCP 23Password: Cisco123! show running-configSSH, TCP 229f 3a c1 07 e2 5d 8b 44 0c d9 71 a6 ...SNMP managerAgentget, UDP 161trap, UDP 162✗v1, v2c: a community string in plain text✓v3: users, authentication and encryptionCopy a filePortLoginEncryptedTFTPUDP 69nonenoFTPTCP 20, 21usernamenoSCP and SFTPTCP 22SSHyesManage network devices only over encrypted channels: SSH for the console, SNMPv3 for monitoring, SCP or SFTP for files.Telnet, SNMPv1 and v2c, TFTP and FTP send passwords as readable text, so anyone who can capture the traffic can log in.Restrict management to a dedicated network or VLAN, and allow it only from known addresses (an ACL on the vty lines).

Use SSH instead of Telnet, SNMPv3 instead of v1 or v2c, and SCP or SFTP instead of TFTP or FTP.

Lesson complete

You finished “DNS, DHCP and NAT”

Nicely done.

Open in a new tab