Find a course

Module 4: Core Network ServicesLesson 9 of 1313 min

DHCP and DNS

Follow the four DHCP steps that configure a device automatically, then see how DNS resolves names through root, TLD and authoritative servers.

Step 1 of 13Learn

Configured without lifting a finger

When you join a Wi-Fi network at a hotel, your phone needs four pieces of information before it can do anything: an IP address, a subnet mask, a default gateway and the address of a DNS server. You never type any of them. A protocol called DHCP (Dynamic Host Configuration Protocol) supplies them in a fraction of a second.

DHCP works in four steps, remembered as DORA:

  1. Discover. The new device has no address yet, so it broadcasts: "Is there a DHCP server here?"
  2. Offer. A DHCP server (usually your router at home, a dedicated server in offices) replies with an available address and settings.
  3. Request. The device broadcasts that it accepts that offer. Broadcasting lets any other DHCP servers know their offers were declined.
  4. Acknowledge. The server confirms, and the device configures itself.

The address is given as a lease for a limited time, from an hour to several days. The device renews it automatically, typically when half the lease has passed. When devices leave, their addresses return to the pool for reuse.

For printers, servers and other devices that others need to find at a fixed address, admins either set a static IP outside the DHCP pool or create a DHCP reservation that always gives the same address to a specific MAC address. If two devices end up with the same address, you get an IP conflict and both behave erratically.

Step 2 of 13Practice · Put in order

Put the four DHCP messages in the order they occur.

Drag the items, or use the arrow buttons, to put them in order.

  1. Discover
  2. Request
  3. Acknowledge
  4. Offer

Step 3 of 13Diagram

DHCP in four messages (DORA)

DHCP in four messages (DORA)Process diagram: Discover → Offer → Request → Acknowledge.DiscoverOfferRequestAcknowledge

Tap a shape with to see more.

Discover

The new device broadcasts: "Is there a DHCP server?"

Offer

A server proposes an address and settings.

Request

The device asks for that offer, telling any other servers it chose this one.

Acknowledge

The server confirms the lease: IP, mask, gateway, DNS servers and lease time.

Step 4 of 13Learn

DNS: the internet's phone book

People remember names like example.com; networks route by IP addresses like 203.0.113.10. The Domain Name System (DNS) translates between them. It is distributed across millions of servers worldwide, organized as a hierarchy read from right to left:

  • The root (an invisible dot at the end: www.example.com.) is served by 13 named root server identities, run as hundreds of copies around the world.
  • Top-level domains (TLDs) such as .com, .org, .net and country codes like .uk or .de.
  • Second-level domains such as example in example.com, registered by organizations and people.
  • Subdomains such as www, mail or shop, created freely by the domain owner.

Each domain has authoritative name servers that hold its official records. Most lookups never travel the whole tree because of caching: your browser, your operating system and your DNS resolver all remember recent answers for as long as each record's TTL (time to live, in seconds) allows. That's why a DNS change can take minutes to hours to be seen everywhere, depending on the TTL that was set.

DNS normally uses UDP port 53. Newer options encrypt lookups for privacy: DNS over HTTPS (DoH) and DNS over TLS (DoT).

Step 5 of 13Practice · Put in order

Your laptop looks up shop.example.org and nothing is cached anywhere. Put the resolution steps in order.

Drag the items, or use the arrow buttons, to put them in order.

  1. The resolver asks a root server, which refers it to the .org servers
  2. The resolver asks example.org's authoritative server, which returns the IP address
  3. The resolver asks a .org TLD server, which refers it to example.org's name servers
  4. The resolver caches the answer and returns it to the laptop
  5. The laptop asks its configured recursive resolver

Step 6 of 13Practice · Diagram

DNS is a tree read from right to left

Which servers hold the actual record for shop.example.org?

Tap the shape that answers the question, then press Check.

DNS is a tree read from right to leftHierarchy diagram: Root (.), .org, .com, example.org, shop.example.org, www.example.org, example.com.Root (.).org.comexample.orgshop.example.orgwww.example.orgexample.com
Root (.)

Knows where every top-level domain's servers are.

.org
.com
example.org

Its authoritative servers hold the zone records.

shop.example.org

An A or AAAA record gives its address.

www.example.org
example.com

Step 7 of 13Learn

DNS record types

A domain's DNS zone holds records of different types. The ones you'll meet most:

TypePurposeExample
Aname → IPv4 addressshop.example.com → 203.0.113.10
AAAAname → IPv6 addressshop.example.com → 2001:db8::10
CNAMEalias pointing to another namewww.example.com → example.com
MXmail servers for the domain, with prioritiesexample.com → 10 mail.example.com
TXTfree text, used for verification and email security (SPF, DKIM, DMARC)"v=spf1 include:... -all"
NSthe authoritative name servers for the domainexample.com → ns1.dnshost.net
PTRreverse lookup: IP address → name10.113.0.203.in-addr.arpa → shop.example.com

A few practical points. A CNAME can't sit at the bare domain (example.com) alongside other records, which is why some providers offer special "alias" records there. MX records must point to a name, not directly to an IP address. And lowering a record's TTL a day before a planned server move makes the switch take effect faster.

Command-line tools let you query DNS directly: nslookup example.com works on Windows, macOS and Linux, and dig example.com (Linux and macOS) shows more detail, including the TTL. dig MX example.com asks for a specific record type.

Step 8 of 13Practice · Match the pairs

Match each DNS record type to its purpose.

Tap an answer, then tap the place where it belongs (or drag it there).

  1. A
  2. AAAA
  3. CNAME
  4. MX
  5. TXT
  6. NS

Step 9 of 13Note

Step 10 of 13Practice · Work it out

A DNS record has a TTL of 3600. You change the record at 9:00 a.m. In the worst case, how many minutes could a resolver that cached the old answer just before your change keep serving it?

Step 11 of 13Diagram

Common DNS TTL choices

Common DNS TTL choicesScale: 60 s, 5 min, 1 hour, 1 day.1010²10³10⁴10⁵60 s60 s300 s5 min3,600 s1 hour86,400 s1 day

Tap a shape with to see more.

Shorter TTLs mean faster changes but more DNS queries.
60 s

Lowered a day or so before a planned migration so changes spread fast.

5 min

Records that change often, such as failover setups.

1 hour

A common default.

1 day

Stable records such as MX and NS.

Step 12 of 13Note

Step 13 of 13Practice · What would you do?

What would you do?

Employees can open websites by IP address but not by name. ipconfig /all on a PC shows the DNS server as 192.168.50.53, an old server that was retired last week. What is the best fix?