Network Ports, 80 and 443
Level 2 · Addresses and ports
What a port number is and how one server runs many programs on one address. The ports to know: 22, 80 and 443, and why most should stay shut.
Course contentsLesson 5 of 13
Level 1 · Networks and packets
Level 2 · Addresses and ports
Level 3 · How data travels
Level 4 · HTTP, the language of the web
Level 5 · Locked lines and go-betweens
After this lesson you can
- Say what a port number picks out
- Name the ports for SSH, HTTP and HTTPS
- Explain why unused ports stay closed
10 mincovers 1 glossary entries
Worth reading first: Private IPs, NAT and DHCP
What a port number picks out
An IP address finds the machine. A port number finds the program on it. Each port is a number from 0 to 65535. A web page asks for port 443, a remote login asks for port 22, and both can reach the same server at the same address. The port tells the server which program should answer.
An address with its port is written with a colon, such as 203.0.113.10:443. Most of the time you never see the port, because each kind of traffic has a usual number. A browser asks for 80 for plain web pages and 443 for secure ones, without being told.
A few ports are worth learning by heart. Port 22 is SSH, for logging in to a server. Port 80 is plain HTTP. Port 443 is HTTPS. Port 53 is for looking up names. Databases have their own, such as 5432 for PostgreSQL and 3306 for MySQL.
A program that waits for requests on a port is said to listen on it. A web program listens on 80 and 443. If nothing listens on a port, a request to it gets no answer. Two programs cannot listen on the same port on the same address at once.
Your own computer uses ports too. When your browser connects to a server, it picks a high, random port on your side, such as 51,734, for the replies to come back to. That is why one laptop can have twenty tabs open to the same site.
Every port that answers from the outside is a door someone can knock on. Attackers scan the whole internet for open ones, all day. So a server should answer only on the ports it really needs, often just 22, 80 and 443.
A common mistake is to leave a database port open to the world because it worked that way in testing. The database should answer only to the app that uses it. Bots find an open database port within hours. They try every password they know.
Worked example
Lucy checks her new server
Lucy rents a server and runs a scan against it from her laptop. It shows ports 22, 80, 443 and 5432 answering.
Her shop only needs the first three. She closes 5432, so the database now answers only to the shop's own code on the same machine.
The words for this lesson1
Check yourself
One server runs a website and a login service at the same address. How do requests reach the right one?
Finished this lesson?
Marking it complete also marks its 1 glossary entries learned, which updates your roadmap and your saved page. 0 are already marked.