How the Internet Works

Lesson 2 of 5

IP Addresses and DNS

Discover the global address book that turns human names into numerical internet coordinates.

🟢 Beginner 60 XP

Learn it

Computers do not understand names like codequest.co.uk. Instead, they rely on numbers called IP addresses, which work just like postal postcodes for machines.

Because memorising strings of numbers is tough for humans, the internet uses the Domain Name System (DNS). It acts like a giant, super-fast contacts list that translates readable names into numerical addresses in a fraction of a second.

Key terms

IP Address
A unique numerical identifier assigned to every device connected to an IP network.
DNS (Domain Name System)
The decentralised naming system that translates human-readable domain names into IP addresses.
A Record
A specific DNS record type that maps a domain name directly to an IPv4 address.
Resolver
A local DNS server, often run by your ISP, that fetches DNS records on behalf of a client.

Tracing a Domain Lookup

Use command-line tools to discover the IP address behind common web domains.

  1. 1Open Terminal or Command Prompt: Launch your system terminal (macOS/Linux) or Command Prompt (Windows).
  2. 2Run nslookup: Type 'nslookup example.com' and press Enter to query your default DNS server.
  3. 3Inspect the Response: Observe the Non-authoritative answer providing an IPv4 address (like 93.184.216.34).
  4. 4Test an IPv6 Lookup: Try 'nslookup -type=AAAA google.com' to observe 128-bit hexadecimal addresses.

Resolving an IP in Python

pythonimport socket

domain = "example.com"
ip_address = socket.gethostbyname(domain)

print(f"Domain: {domain}")
print(f"Resolved IPv4 Address: {ip_address}")

Python's built-in socket library contacts your operating system's DNS resolver to fetch the matching IP address for a host name.

Try it

Match each DNS/IP component with its correct function:

IPv4 Address
DNS Resolver
A Record
TLD Server

Challenge

Write a short Python script that takes a list of three domain names and prints each domain with its resolved IP address.

Pick whichever way suits you — every mode earns the same bonus XP.

Write at least 40 more characters to submit.

Mark your own work

Guided walkthrough — 0/5 clues revealed

  1. Clue 1 locked — reveal it only if you get stuck.
  2. Clue 2 locked — reveal it only if you get stuck.
  3. Clue 3 locked — reveal it only if you get stuck.
  4. Clue 4 locked — reveal it only if you get stuck.
  5. Clue 5 locked — reveal it only if you get stuck.

Each clue costs 3 XP (never below 15 XP). You'd earn 30 XP right now.

Extension: Add exception handling with try/except socket.gaierror to gracefully catch invalid or non-existent domains.

Quiz time

Question 1 of 4Score 0

What is the primary function of the Domain Name System (DNS)?