MarzleyTech Learn

Home / Learn / Networking / DNS and DHCP: how names become addresses and how devices get IP settings automatically

DNS and DHCP: how names become addresses and how devices get IP settings automatically

Two services make networks usable for ordinary people:

  • DNS (Domain Name System) turns names like www.kra.go.ke into IP addresses. Without it, you'd type numbers to visit every website.
  • DHCP (Dynamic Host Configuration Protocol) gives devices their IP address, mask, gateway and DNS servers automatically when they join a network. Without it, someone would have to configure every phone that connects to the office Wi-Fi by hand.

When "the internet is down", the cause is very often one of these two. This unit explains how both work in detail, how to configure them, and how to troubleshoot them.


Part 1: DNS

The DNS hierarchy

DNS is a worldwide, distributed database organised as a tree, read from right to left:

www.marzleytechsolutions.co.ke.
 |          |            |  |  └── root (.)
 |          |            |  └───── top-level domain (TLD): ke
 |          |            └──────── second level: co (under .ke)
 |          └───────────────────── the domain: marzleytechsolutions
 └──────────────────────────────── host/subdomain: www
LevelWho runs itExamples
Root servers13 named root server identities, operated worldwide with many copies (anycast).
TLD serversRegistries.com, .org, .ke (run by KENIC)
Second-level under .keKENIC.co.ke, .go.ke, .ac.ke, .or.ke, .ne.ke, .sc.ke
Authoritative serversThe domain owner's DNS hostHolds the actual records for a domain

Resolvers and a lookup step by step

Your device asks a recursive resolver (your ISP's, or a public one like 8.8.8.8, 1.1.1.1 or 9.9.9.9), which does the work:

  1. You type www.example.co.ke. Your device checks its own cache; if not found, it asks the resolver.
  2. The resolver checks its cache. If not found, it asks a root server: "Where's .ke?"
  3. The root replies with the .ke TLD servers.
  4. The resolver asks a .ke server; it replies with the servers for co.ke, which point to the domain's authoritative name servers.
  5. The resolver asks the authoritative server, which replies: www.example.co.ke = 203.0.113.10.
  6. The resolver caches the answer and returns it to your device. Your browser connects to 203.0.113.10.

All this usually takes milliseconds, and caching means most lookups are answered from step 1 or 2.

Caching and TTL

Each record has a TTL (time to live) in seconds: how long resolvers may cache it. A TTL of 3600 means changes may take up to an hour to be seen everywhere. Before moving a website to a new server, lower the TTL (e.g. to 300) a day ahead so the switch is fast. "DNS propagation" is really caches expiring.

Record types

RecordPurposeExample
AName → IPv4 addresswww → 203.0.113.10
AAAAName → IPv6 addresswww → 2001:db8::10
CNAMEAlias to another nameshop → myshop.platform.com
MXMail servers for the domain, with priority@ → 10 mail.example.co.ke
TXTText for verification and email securitySPF v=spf1 include:_spf.google.com ~all, DKIM, DMARC, site verification
NSAuthoritative name servers for the domainns1.host.co.ke
PTRReverse lookup: IP → nameMail servers need correct PTRs
SRVLocation of a service (host and port)VoIP, Microsoft 365
CAAWhich certificate authorities may issue SSL certificates0 issue "letsencrypt.org"
SOAZone information (primary server, serial number, timers)One per zone

@ means the domain itself (e.g. example.co.ke).

Practical DNS for a small business

A company with a website on a hosting server and email on Google Workspace or Microsoft 365 needs, at minimum:

  • A records for @ and www (or www as a CNAME) pointing to the web host.
  • MX records from the email provider.
  • TXT records for SPF, DKIM and DMARC so their emails don't land in spam.
  • Correct NS records at the registrar pointing to whoever hosts the DNS.

Local name resolution

Before DNS, computers check the hosts file (C:\Windows\System32\drivers\etc\hosts or /etc/hosts). Developers use it to test sites (203.0.113.10 www.example.co.ke). Malware sometimes edits it to redirect banking sites, so check it if one site behaves strangely.


Part 2: DHCP

What DHCP provides

When a device joins, DHCP gives it:

  • IP address and subnet mask
  • Default gateway (router)
  • DNS server(s)
  • Lease time (how long it may keep the address)
  • Optional extras: domain name, NTP server, TFTP server for IP phones (option 66/150), etc.

DORA: how a device gets an address

StepMessageFrom → ToMeaning
DDiscoverClient → broadcast (255.255.255.255)"Is there a DHCP server? I need an address"
OOfferServer → client"You can have 192.168.1.57"
RRequestClient → broadcast"I'd like 192.168.1.57 please" (broadcast so other servers know)
AAcknowledgeServer → client"It's yours for 24 hours"

DHCP uses UDP ports 67 (server) and 68 (client).

Leases and renewal

  • At 50% of the lease, the client tries to renew with the same server; at 87.5% it asks any server.
  • Short leases (1–8 hours) suit busy guest Wi-Fi with many visitors; longer leases (1–8 days) suit stable office PCs.
  • If a client gets no answer at all, Windows assigns itself an APIPA address (169.254.x.x): a sign DHCP failed.

Scopes, exclusions and reservations

  • Scope (pool): the range handed out, e.g. 192.168.1.50 – 192.168.1.250.
  • Exclusions: addresses inside the subnet not to hand out (kept for static devices).
  • Reservation: a specific device (by MAC address) always gets the same IP, e.g. the office printer at 192.168.1.20. Easier to manage than static configuration on the device itself.

Where DHCP runs

NetworkDHCP server
HomeThe ISP router
Small officeRouter or firewall
EnterpriseWindows Server DHCP, ISC Kea, or the core switch/firewall

DHCP relay

DHCP Discover is a broadcast, and routers don't forward broadcasts. In networks with many VLANs and one central DHCP server, each router interface is configured as a DHCP relay (Cisco: ip helper-address 10.1.50.10), which forwards the requests to the server as unicast.

Example: Cisco router as a DHCP server

ip dhcp excluded-address 192.168.10.1 192.168.10.49
ip dhcp pool LAB1
 network 192.168.10.0 255.255.255.0
 default-router 192.168.10.1
 dns-server 8.8.8.8 1.1.1.1
 lease 1

Troubleshooting

DNS

Terminal
nslookup www.example.co.ke             # which IP? which DNS server answered?
nslookup -type=MX example.co.ke        # mail servers
nslookup www.example.co.ke 8.8.8.8     # ask a specific resolver
dig www.example.co.ke +short           # Linux/macOS
ipconfig /displaydns                   # Windows DNS cache
ipconfig /flushdns                     # clear it after DNS changes

Symptoms of DNS trouble: websites fail by name but ping 8.8.8.8 works; "DNS_PROBE_FINISHED_NXDOMAIN" in Chrome; some sites work and others don't after a change.

DHCP

Terminal
ipconfig /all              # Windows: is DHCP enabled? which server? lease times?
ipconfig /release
ipconfig /renew
ip a ; ip r                # Linux
SymptomLikely cause
169.254.x.x addressNo DHCP server reachable: cable, VLAN, relay, or server down
Wrong subnet address (e.g. 192.168.0.x instead of 10.1.x.x)A rogue DHCP server (someone plugged in a home router)
"No addresses available" / new devices can't connectScope exhausted: lengthen the pool or shorten leases
IP conflict warningsStatic device inside the DHCP pool: use exclusions/reservations

Security

  • DNS filtering (e.g. family-safe or malware-blocking resolvers) blocks known bad domains for a whole school or office.
  • DNSSEC signs DNS records so resolvers can detect forged answers.
  • DNS over HTTPS/TLS encrypts lookups so others on the network can't see or tamper with them.
  • DHCP snooping on managed switches allows DHCP offers only from trusted ports, stopping rogue DHCP servers.
  • Protect your domain registrar account with a strong password and 2-step verification: whoever controls your DNS controls your website and email.
Think about it: After a company moves its website to a new host, some staff see the new site and others still see the old one for several hours. Why, and how could it have been avoided?Show answer

DNS caching: resolvers and devices keep the old A record until its TTL expires. Lowering the TTL (e.g. to 300 seconds) a day before the move would have made the change take effect within minutes. Staff can also flush their local cache with ipconfig /flushdns.

Summary

  • DNS translates names to IPs through a hierarchy: root → TLD (.ke) → authoritative servers, via a caching recursive resolver.
  • TTL controls caching; key records: A, AAAA, CNAME, MX, TXT, NS, PTR, SRV, CAA.
  • DHCP gives IP, mask, gateway and DNS using DORA on UDP 67/68, with leases, scopes, exclusions and reservations.
  • Routers need DHCP relay (ip helper-address) for central servers; 169.254.x.x means DHCP failed.
  • Troubleshoot with nslookup/dig and ipconfig; secure with DNS filtering, DNSSEC, encrypted DNS and DHCP snooping.

Check yourself

  1. What do the letters DORA stand for? (four words)

    Show answer

    Discover Offer Request Acknowledge

  2. Which DNS record maps a name to an IPv4 address?

    Show answer

    A

  3. Which DNS record lists a domain's mail servers?

    Show answer

    MX

  4. Which record type is an alias from one name to another?

    Show answer

    CNAME

  5. A printer must always get the same address from DHCP. What is this called?

    Show answer

    reservation

  6. Which record type maps a name to an IPv6 address?

    Show answer

    AAAA

  7. Which organisation runs the .ke domain registry?

    Show answer

    KENIC

  8. Which Windows command clears the DNS cache?

    Show answer

    ipconfig /flushdns

Learn more: Cloudflare: What is DNS? · Cloudflare: What is DHCP?

Lesson 14 of 24 in Networking · Written by · Course notes