Internet Intermediate: Protocols, Networks and APIs
Local Networks, DHCP and NAT
In this lesson you will
- Describe private address ranges and subnets
- Explain what DHCP and NAT do
- Read a simple CIDR address like 192.168.1.0/24
Introduction
Your phone, laptop and TV all share one internet connection, but the internet sees only one address from your home. How does that work? The answer involves private addresses, a router that hands them out, and a trick called NAT.
Private addresses
Some IPv4 ranges are reserved for private use. They work inside homes and organisations, and are not routed on the public internet:
10.0.0.0to10.255.255.255(written10.0.0.0/8)172.16.0.0to172.31.255.255(172.16.0.0/12)192.168.0.0to192.168.255.255(192.168.0.0/16)
Many home networks use 192.168.0.x or 192.168.1.x. Because they are not unique worldwide, millions of homes can reuse them.
Subnets and CIDR
A subnet is a group of addresses on the same local network. CIDR notation describes it with a prefix length:
192.168.1.0/24The number after the slash says how many bits identify the network. The rest identify the host. For IPv4, /24 leaves 8 bits for hosts, which means 256 addresses (254 usable, since the first is the network name and the last is for broadcast). A /16 has 65,536 addresses, and a /30 has just 4.
Devices on the same subnet talk directly. To reach anything else, they send traffic to the default gateway, usually the router.
Quick quiz
How many addresses are in a /24 IPv4 subnet?
DHCP: automatic addressing
Typing an address into every device would be painful. DHCP (Dynamic Host Configuration Protocol) does it automatically. When a device joins the network:
- It broadcasts "I need an address".
- The DHCP server, usually your router, offers one.
- The device accepts, and receives the address, the subnet details, the default gateway and the DNS server to use.
Addresses are leased for a time, then renewed. You can reserve a fixed address for a device, such as a printer, in the router settings.
The router and the gateway
Your home router combines several roles: a router between your local network and the internet, a DHCP server, a firewall, often a Wi-Fi access point and a NAT device.
NAT: sharing one public address
Your internet provider gives your router one public IP address. Many devices share it using network address translation (NAT):
- Your laptop (
192.168.1.20) sends a request to a website. - The router rewrites the source address to its public address and remembers which internal device and port the request came from, in a translation table.
- The reply returns to the router, which looks up the table and forwards it to the laptop.
Side effects:
- Devices behind NAT are not directly reachable from the internet, which gives some protection, but it is not a firewall in itself.
- To run a server at home, you configure port forwarding, telling the router to send certain incoming ports to a specific device. Do this carefully.
- NAT helped the world cope with the shortage of IPv4 addresses. IPv6 has so many addresses that NAT is not needed.
How devices find each other locally
On an IPv4 Ethernet or Wi-Fi network, ARP (Address Resolution Protocol) maps an IP address to the hardware (MAC) address of the device that has it, so frames can be delivered on the local link.
Try it yourself
On your computer, find your local IP address and default gateway (ipconfig on Windows, or ip addr and ip route on Linux). Then search the web for "what is my IP" and compare. Explain why they differ.
Summary
- Private ranges such as 192.168.0.0/16 are used locally, and CIDR notation describes subnet size.
- DHCP automatically gives devices an address, gateway and DNS server.
- NAT lets many devices share one public address, and IPv6 removes the need for it.
Lesson complete
+20 XP
Nice work. Keep going while it is fresh.
Sources and further reading