Explain the Role of DHCP and DNS Within the Network

Explain the role of DHCP and DNS within the network

Two services quietly do most of the heavy lifting every time a device joins a network and a user types a website name into a browser: DHCP, which hands out IP addressing automatically, and DNS, which translates human-friendly names into machine-usable IP addresses. Without them, we’d all be manually configuring IP addresses and memorizing numeric addresses like 142.250.190.14 instead of typing google.com.

This article focuses on the conceptual role each service plays in the network and how they work together, complementing the deeper configuration-focused articles on DHCP client/relay elsewhere in this series.

The Two Problems Being Solved

ProblemSolved By
“How does this device get an IP address and network settings automatically?”DHCP
“How does a name like www.example.com get turned into an IP address a computer can actually route to?”DNS

These are fundamentally different problems, but they are deeply connected in daily operation: when DHCP hands a device its configuration, one of the values it commonly provides is which DNS server to use.

The Role of DHCP in the Network

DHCP’s job is addressing automation. When a device connects to a network, it needs:

Without DHCP, every device joining the network would require manual configuration — completely impractical for large networks, guest Wi-Fi, or BYOD (Bring Your Own Device) environments where devices come and go constantly.

sequenceDiagram
    participant Client
    participant DHCP Server
    Client->>DHCP Server: DHCPDISCOVER
    DHCP Server-->>Client: DHCPOFFER (IP, Gateway, DNS server)
    Client->>DHCP Server: DHCPREQUEST
    DHCP Saerver-->>Client: DHCPACK
    Note over Client: Client is now fully configured,
including which DNS server to use

The Role of DNS in the Network

DNS’s job is name resolution. Humans remember names; computers route based on IP addresses. DNS is the distributed, hierarchical database that maps one to the other.

When you type www.example.com into a browser:

  1. Your computer checks its local DNS cache.
  2. If not cached, it asks the DNS server it was given (often via DHCP).
  3. That DNS server may query other servers up the DNS hierarchy (root servers → TLD servers → authoritative servers) if it doesn’t already know the answer.
  4. The IP address is returned, and your browser then makes an actual connection to that IP.
flowchart TD
    A[User types www.example.com] --> B{In local cache?}
    B -- Yes --> F[Use cached IP]
    B -- No --> C[Query configured DNS Server]
    C --> D{DNS Server knows answer?}
    D -- Yes --> F
    D -- No --> E[Query Root -> TLD -> Authoritative Server]
    E --> F
    F --> G[Browser connects to resolved IP address]

How DHCP and DNS Work Together

This is the key conceptual point: DHCP is often the mechanism that tells a device which DNS server to use. The two protocols are separate, but DHCP is frequently the delivery vehicle for DNS configuration.

ip dhcp pool LAN-POOL
 network 192.168.10.0 255.255.255.0
 default-router 192.168.10.1
 dns-server 8.8.8.8 8.8.4.4     -- DHCP delivering DNS server info
 domain-name company.local

Additionally, in many enterprise environments, DHCP and DNS are integrated further through Dynamic DNS (DDNS) updates — when a DHCP server assigns an address to a device, it can automatically register that hostname-to-IP mapping in DNS, so other devices on the network can reach that host by name without any manual DNS record creation.

DNS Record Types You Should Know

Record TypePurposeExample
AMaps a hostname to an IPv4 addresswww.example.com → 93.184.216.34
AAAAMaps a hostname to an IPv6 addresswww.example.com → 2606:2800:220:1::
CNAMEMaps an alias name to another hostnameblog.example.com → www.example.com
MXSpecifies mail servers for a domainexample.com → mail.example.com
PTRReverse lookup: IP address to hostname34.216.184.93.in-addr.arpa → www.example.com
NSSpecifies authoritative name servers for a domainexample.com → ns1.example.com
SOAStart of Authority — defines zone administrative infoSerial number, refresh, retry, expire settings

Configuring DNS on a Cisco Router

As a DNS Client (Router Resolving Names)

Router(config)# ip domain-lookup
Router(config)# ip name-server 8.8.8.8 8.8.4.4
Router(config)# ip domain-name company.local

Verify:

Router# show hosts
Router# show running-config | include name-server

Test it:

Router# ping www.cisco.com
Translating "www.cisco.com"...domain server (8.8.8.8) [OK]

Disabling DNS Lookup (Common Troubleshooting Step)

A classic beginner mistake: typing a command wrong on a Cisco CLI, and the router hangs for a long time trying to resolve the mistyped word as a hostname before returning to the prompt. Disabling this behavior speeds up console work significantly:

Router(config)# no ip domain-lookup

DHCP + DNS Integration on Linux

DHCP Client Requesting Configuration Including DNS

sudo dhclient eth0
cat /etc/resolv.conf

Example /etc/resolv.conf populated automatically via DHCP:

nameserver 8.8.8.8
nameserver 8.8.4.4
search company.local

Running a DNS Resolver on Linux (dnsmasq — Combined DHCP + DNS)

dnsmasq is a popular lightweight tool that provides both DHCP and DNS in one package — commonly used in small offices, labs, and home routers.

sudo apt install dnsmasq -y
sudo nano /etc/dnsmasq.conf
interface=eth0
dhcp-range=192.168.10.50,192.168.10.150,12h
dhcp-option=option:router,192.168.10.1
dhcp-option=option:dns-server,192.168.10.1
server=8.8.8.8
domain=company.local

This single service both assigns IP addresses via DHCP and answers DNS queries — with the DHCP configuration directly telling clients to use the same box (192.168.10.1) for DNS resolution, demonstrating the tight integration between the two services in a real deployment.

sudo systemctl restart dnsmasq
sudo systemctl status dnsmasq

Verifying the Combined DHCP + DNS Flow

# Check what IP and DNS server a client received
ip addr show eth0
cat /etc/resolv.conf

# Test name resolution using the assigned DNS server
nslookup www.example.com
dig www.example.com

Example dig output:

;; ANSWER SECTION:
www.example.com.    300    IN    A    93.184.216.34

Automating DNS Lookups with Python

import socket

hostnames = ["www.google.com", "www.cisco.com", "example.com"]

for host in hostnames:
    try:
        ip = socket.gethostbyname(host)
        print(f"{host} -> {ip}")
    except socket.gaierror:
        print(f"{host} -> Resolution failed")

Output:

www.google.com -> 142.250.190.14
www.cisco.com -> 72.163.4.185
example.com -> 93.184.216.34

This simple script mirrors what happens automatically, thousands of times per second, whenever browsers, apps, and network devices need to resolve names — and is a useful building block for automated connectivity health checks.

Comparison Table: DHCP vs DNS

AspectDHCPDNS
Core FunctionAutomatic IP address & network configuration assignmentName-to-IP address resolution
TransportUDP ports 67/68UDP/TCP port 53
Data DirectionClient requests, server assigns (leases)Client queries, server responds
Typical Failure SymptomNo IP address (APIPA, 169.254.x.x)Device has connectivity but “site not found” errors
RelationshipFrequently delivers DNS server address to clientsFrequently relies on DHCP-provided server info

Real-World Scenario Illustrating the Relationship

A user reports: “My laptop can’t reach any websites, but I can ping IP addresses fine.”

This is a classic symptom that separates the two services clearly:

  1. Since connectivity works via IP address, DHCP has clearly succeeded — the device has a valid IP, subnet mask, and gateway, and basic routing is functioning.
  2. Since name-based access fails, the issue is isolated specifically to DNS — either the DNS server address is wrong/unreachable, or the DNS server itself is failing to resolve queries.

This diagnostic logic — “if IP works but names don’t, suspect DNS; if nothing works at all, suspect DHCP/addressing” — is one of the most useful troubleshooting heuristics in networking.

Best Practices

Troubleshooting

SymptomLikely Service at FaultFix
No IP address at allDHCPCheck DHCP server/relay, verify pool isn’t exhausted
IP address works, but browsing fails, ping by IP worksDNSCheck DNS server reachability, nslookup/dig test
Some sites resolve, others don’tDNS (specific record issue) or client cacheFlush DNS cache, check specific record with dig
Wrong DNS server assignedDHCP configuration errorVerify dns-server line in DHCP pool config
DNS resolves, but connection times outNot DNS’s fault — routing/firewall issueContinue troubleshooting at IP/transport layer

Conclusion

DHCP and DNS solve two distinct but deeply complementary problems: DHCP automates network addressing so devices don’t need manual configuration, and DNS translates human-readable names into the IP addresses that routing actually depends on. In practice, they are tightly linked — DHCP is usually the very mechanism that tells a client which DNS server to use. Understanding both their individual roles and how they interact is fundamental to diagnosing connectivity issues correctly and building networks that “just work” for end users.

References

  1. RFC 2131 – Dynamic Host Configuration Protocol — https://datatracker.ietf.org/doc/html/rfc2131
  2. RFC 1035 – Domain Names, Implementation and Specification — https://datatracker.ietf.org/doc/html/rfc1035
  3. Cisco DNS Configuration Guide — https://www.cisco.com/c/en/us/td/docs/ios-xml/ios/ipaddr_dns/configuration/xe-16/dns-xe-16-book.html
  4. dnsmasq Documentation — https://thekelleys.org.uk/dnsmasq/doc.html
  5. Google Public DNS Documentation — https://developers.google.com/speed/public-dns
  6. DNSSEC Overview — https://www.icann.org/resources/pages/dnssec-what-is-it-why-important-2019-03-05-en
Exit mobile version