Course outline · 0% complete

0/25 lessons0%

Course overview →

IP addresses

lesson 2-1 · ~10 min · 3/25

Quiz

Warm-up from lesson 1-2: in the six-step journey of a page load, why does the DNS lookup have to happen before the HTTP request?

Every machine gets a number

An IP address (Internet Protocol address) is the number that identifies a computer on a network. If a URL is like a business name, the IP address is the street address that mail actually gets delivered to.

The common format, IPv4, is four numbers from 0 to 255 separated by dots:

93.184.215.14

Each of the four parts is called an octet because it fits in 8 bits (2⁸ = 256 possible values, 0 to 255). Four octets means 32 bits total, so an IPv4 address is really just one 32-bit number written in a human-friendly way. There are about 4.3 billion possible IPv4 addresses, which turned out not to be enough for the whole world. The newer IPv6 format fixes that with 128-bit addresses written in hex, like 2606:2800:21f:cb07::1. You will mostly see IPv4 in examples, and everything you learn applies to both.

You will read IP addresses constantly on the job: in server logs, in config files, and in error messages like connection refused to 10.0.5.20:5432. Being able to glance at one and know what kind of machine it points at is a real debugging skill, and the next section gives you the first rule for it.

Code exercise · bash

Run this. It splits an IPv4 address into its four octets, then rebuilds the single 32-bit number the dots are hiding. IFS='.' tells read to split on dots, and << shifts bits left (a << 24 moves the first octet into the top 8 bits).

Private vs public addresses

Not every IP address is reachable from the whole internet. Three ranges are reserved for private networks (your home Wi-Fi, an office LAN):

RangeExample
10.x.x.x10.0.5.20
172.16.x.x to 172.31.x.x172.20.1.1
192.168.x.x192.168.1.7

Your laptop probably has a private address like 192.168.1.7 right now. Your home router shares one public address with every device behind it (a trick called NAT, network address translation). Two special addresses worth knowing: 127.0.0.1 always means "this same machine" (called localhost), and 8.8.8.8 is Google's public DNS server, a favorite for connectivity tests.

When a server "cannot be reached", one early question is: am I trying to reach a private address from outside its network? That never works.

Code exercise · bash

Your turn. Fill in the if condition so the script labels each address private or public using the three ranges from the table: first octet 10, or first octet 192 with second octet 168, or first octet 172 with second octet between 16 and 31.

Quiz

A teammate's error log says "connection to 127.0.0.1:5432 refused". Which machine was the program trying to reach?