Is it the address or the port?
A support ticket arrives: "The order page will not load." Your team lead reads it and asks one question. "Is it the address or the port?"
Every message on a network needs two numbers to arrive. One finds the computer. The other finds the program on it. In this lesson you learn to read both.
By the end of this lesson
Note
I can say what an IP address and a port are.
Key words
| Word | What it means | Example |
|---|---|---|
| Server | a computer that answers requests | |
| Client | the program that sends a request | |
| IP address | the number that names a device on a network | 192.168.1.23 |
| Port | the number that names one program on a device | 443 |
| Socket | an IP address and a port together | 203.0.113.10:443 |
| IPv6 | the newer, longer kind of IP address | 2001:db8::10 |
The cells students fill in are left blank in this preview.
An IP address names a device
Every device on a network has an IP address. Laptops, phones, printers and servers all have one.
The common kind, IPv4, is four numbers with dots between them, like 192.168.1.23. Each number is from 0 to 255.
IPv6 addresses are longer and use letters too, like 2001:db8::10. They exist because the world ran short of IPv4 addresses.
Worked example: one small office
| Device | IP address | What it does |
|---|---|---|
| Sales laptop | 192.168.1.23 | Sends requests |
| Office printer | 192.168.1.40 | Takes print jobs |
| Router | 192.168.1.1 | Links the office to the internet |
| Shop web server | 203.0.113.10 | Answers order requests |
The cells students fill in are left blank in this preview.
Try it: check an address
address = "192.168.1.23"
# split cuts the text at every dot and gives a list of four parts
parts = address.split(".")
print(parts)
for part in parts:
number = int(part)
if number > 255:
print(part, "is too big: each part is 0 to 255")
else:
print(part, "is fine")
# Change the address to "192.168.1.300", then press Run.
A port names a program
One server often runs several programs. It might run a website, a database and a remote login service at the same time.
A port is a number from 1 to 65535. It tells the server which program should get the message. Some numbers are used so widely that everybody knows them. A web server using HTTPS listens on port 443.
Ports you will meet at work
| Port | Service | Used for |
|---|---|---|
| 22 | SSH | Logging in to a server remotely |
| 53 | DNS | Turning names into addresses |
| 80 | HTTP | Web pages, not encrypted |
| 443 | HTTPS | Web pages, encrypted |
| 5432 | PostgreSQL | A database |
The cells students fill in are left blank in this preview.
A common mistake
Warning
Many people think a port is the socket on the back of a computer. Here a port is a number, not a hole for a cable. It lives in the message, and it tells the device which program should read it.
Try it: look up a port
# A small copy of the list of well-known ports
printf "ssh 22\ndns 53\nhttp 80\nhttps 443\npostgres 5432\nmysql 3306\n" > ports.txt
# Which service listens on port 443?
grep " 443$" ports.txt
# Change 443 to 22, then press Run.
Both ends have an address and a port
A socket is an address and a port written together: 203.0.113.10:443.
A connection has a socket at each end. The server's port is fixed and well known. The client picks a high port at random for each connection. That is how one laptop can have ten browser tabs open to the same shop.
Worked example: one connection
| End | IP address | Port | Written as |
|---|---|---|---|
| Client: sales laptop | 192.168.1.23 | 51544 | 192.168.1.23:51544 |
| Server: shop website | 203.0.113.10 | 443 | 203.0.113.10:443 |
The cells students fill in are left blank in this preview.