bastion

Understanding IP Addresses

Build this skill

Decide whether an IPv4 address is public or private, tell IP and MAC addresses apart, and explain how devices get static or DHCP addresses.

An address so the reply can find you

When Mrs. Gokhale taps "Repeat last order", her phone sends a small message to the Tulsi Health server, and the server sends "Order confirmed" back. For that reply to land on her phone and not on someone else's, every device in the conversation needs an address, just as a letter needs one. On networks that address is the IP address, a number given to each device so that data can be delivered to it ("IP" stands for Internet Protocol, the shared rule book for addressing and delivering data). Addresses are also how security tools recognise who is talking to whom, so knowing how they work explains a lot about what a network lets in and what it keeps out.

Reading an IPv4 address like a postal address

The most common kind of address is an IPv4 address, written as four numbers separated by dots, such as 192.168.1.23. Each of the four numbers can be anything from 0 to 255. Behind the scenes the whole address is 32 binary digits (bits), which allows about 4.3 billion different addresses.

An IP address has two parts, rather like a postal address in India. The first part says which network the device is on, the way the PIN code 411038 tells the postman the letter belongs to Kothrud. The last part says which device on that network, the way "Flat 12" tells the local postman which door. In a typical store network, 192.168.1 is the network part shared by every device in the shop and the final number picks the device: .1 for the router, .23 for the billing laptop, .40 for the printer. Routers on the way only need to look at the network part to send data in the right direction, exactly as sorting centres only read the PIN code.

IPv6: more addresses for a crowded world

4.3 billion sounds enormous until you count every phone, laptop, smart TV, CCTV camera and card machine on Earth. The world ran out of fresh IPv4 addresses years ago. The long-term answer is IPv6, whose addresses are 128 bits long, enough to give a practically unlimited number of addresses to every person and device. IPv6 addresses are written as eight groups of four hexadecimal digits (digits 0 to 9 plus the letters a to f) separated by colons, and long runs of zeros can be shortened to ::.

IPv4 address192.168.1.234 numbers, 0 to 255 each32 bits, about 4.3 billionIPv6 address2001:db8:4a1c::238 groups of hex, :: skipszeros128 bits, practicallyunlimitedMAC address3C:52:82:1A:7F:096 pairs, set in the networkcardused only on the localnetwork

Three kinds of address you will see in settings screens and logs. The format alone usually tells you which one you are looking at.

Many Indian mobile networks already give phones IPv6 addresses, so Mrs. Gokhale's phone may well be using one. Both versions run side by side under the same security rules: every address that can be reached from the internet must be protected, and IPv6 must not be forgotten when firewall rules are written only for IPv4.

Public and private addresses

A public IP address is one that is reachable across the internet, unique worldwide and handed out through ISPs (internet service providers). A private IP address is meant only for use inside a local network, and the same private addresses are reused in millions of homes and offices. Three blocks are set aside for private use: any address starting with 10., any starting with 192.168., and those from 172.16. to 172.31.. Routers on the internet are set up not to carry traffic addressed to them.

An apartment society makes this concrete. Every society in Pune has a flat B-204, so "B-204" means nothing to a courier unless it comes with the society's own street address. The flat number is the private address, the society's address is the public one, and the watchman at the gate decides which flat a parcel belongs to.

Kothrud store network private flat numbers inside 192.168.1.1 router .23 billing laptop .40 printer .57 staff phone 203.0.113.45 router Which flat asked for this? Nobody? Then it stays outside. to 203.0.113.45 reply from cloud Flat numbers repeat in every society. Only the gate address is unique on the internet. Private: 10.x, 192.168.x, 172.16 to 172.31.x Public: everything else, one per gate

Inside, every device has a private flat number; outside, the whole store shares the gate's public address. The router at the gate remembers who asked for what and turns away parcels nobody ordered.

The store router plays the watchman through a trick called network address translation (NAT). When the billing laptop at 192.168.1.23 contacts the cloud, the router swaps the private address for the store's single public address, here 203.0.113.45, and notes which laptop asked. When the reply arrives, it looks up its notes and passes the reply to the right laptop. This lets one public address serve the whole shop, and it has a useful side effect for security: a stranger on the internet cannot start a conversation with 192.168.1.23 directly, because that address is meaningless outside the store. NAT is not a full firewall, though. It does nothing about a laptop inside that opens a harmful link, and any device deliberately given a public address, such as the Tulsi Health app server, is exposed to everyone and must be defended on its own.

The small program below reads an IPv4 address, splits it at the dots and checks whether it falls in one of the private blocks. You do not need to know Python to use it: press Run, then change the address on the first line (the comment shows where) and run it again.

python · runs in your browser

Expected output:

text
Part: 192
Part: 168
Part: 1
Part: 23
Private: works only inside a local network
Line What it does
address = ... Stores the address to check. This is the one value to change.
parts = address.split(".") Cuts the text at every dot, giving four separate pieces.
for part in parts: Repeats the next line once for each of the four pieces, printing each one.
first = int(...), second = int(...) Turns the first two pieces from text into numbers so they can be compared.
if first == 10 or ... Checks the three private blocks: starts with 10, starts with 192.168, or 172 followed by 16 to 31.
print(...) Reports which kind of address it is.

Try 203.0.113.45 or 172.20.5.9 and compare the answers. Knowing quickly whether an address is private helps you read a log: a login from a 192.168. address came from inside a network, while one from an unfamiliar public address came from somewhere out on the internet.

Decide for each address below whether it is public or private, and what that means for who can reach it.

MAC addresses: the name on the network card

An IP address is not the only address a device has. Each network card also carries a MAC address, a hardware identifier such as 3C:52:82:1A:7F:09, set at the factory. The two work at different distances. The MAC address is used only to deliver data between devices on the same local network, like a switch handing a message to the right socket. The IP address is used end to end, across the internet. A good way to remember the difference is a person's name and their home address: your name stays with you, while your address changes when you move. Carry the billing laptop from Kothrud to Nashik Road and its MAC address stays the same while its IP address changes.

MAC addresses are easy to change in software, so they are a weak way to decide who is allowed on a network; an attacker can copy an approved device's MAC. Modern phones even show a different, random MAC address to each Wi-Fi network for privacy, so that shops and malls cannot track you as you walk past their hotspots.

How devices get their addresses

A device gets its IP address in one of two ways. A static IP address is typed in by hand and never changes, which suits devices that others must always find, such as the store printer or a server. A dynamic IP address is lent automatically by a service on the router called DHCP (Dynamic Host Configuration Protocol) when the device joins, for a fixed period called a lease, a bit like a hotel reception handing you a room key for the length of your stay.

Joins Wi-FiFarida's phoneAsks DHCPany address free?on arrivalGets a lease192.168.1.57, 24 hrouter answersReturns itlease expireson leavingNext week the same address may go to a different phone

Dynamic addresses are borrowed, not owned. That is convenient, and it means a log line with only an IP address may point to a different device on a different day.

If a suspicious action came from 192.168.1.57 last Tuesday, Neha needs the DHCP records for that day to know which device held the address then. Keeping those records turns an address in a log into a real answer.

Sort the Tulsi Health devices below by whether they should get a fixed address or a borrowed one.

Follow your curiosity.

↑ ↓ to explore · Enter to open · Escape to close