bastion

Network Protocols and Ports

Build this skill

Match common services to their protocol and port, choose between TCP and UDP for a job, and decide which open ports a server should keep.

Rules both sides agree on, and the right window to knock on

The Tulsi Health app server in the cloud does several jobs at once: it shows the app's pages, accepts Rohan's admin logins and keeps a database of orders. When Mrs. Gokhale's phone sends a request, the server's address gets the message to the right computer, but something else must say which of those jobs it is for, and both sides must agree on how the conversation will go. That agreement is a protocol, a fixed set of rules for how two devices exchange a particular kind of message, and the number that picks the job is a port. Together they decide what a server will listen to, which is why a security review of any server starts with its protocols and its open ports.

Ports: counter windows in one building

An IP address gets data to the right device, the way a postal address gets you to the right post office building. Inside, though, there are several counter windows: one for speed post, one for savings accounts, one for parcels. A port is the window number. It is a number from 0 to 65,535 written after the address with a colon, so 198.51.100.20:443 means "the server at that address, window 443". A program on the server that is waiting for messages at a window is said to be listening on that port, and the port is then called open.

Tulsi Health cloud server 198.51.100.20 443 App (HTTPS) ✓ open 80 Web (HTTP) only says: "go to 443" open 22 Admin login ! staff network only 3306 Database ✕ closed Other windows 0 to 65,535: all shut unless a program needs them 198.51.100.20:443 phone's request address : port

The address finds the building; the port picks the window. Every open window is a door someone can knock on, so a careful server opens only the ones it needs.

Common services use well-known port numbers so that clients know where to knock without asking. Web pages are served on port 80 (HTTP) and 443 (HTTPS), name lookups use port 53 (DNS), and remote administrator logins to servers commonly use port 22 (SSH, a protected remote command line). Every open port is a program that strangers can talk to, so each one is a possible way in. A forgotten remote-access port on a billing laptop, or a database port left open to the internet, is one of the most common starting points for real break-ins. The defensive habit is simple: list what is open, ask why, and close or restrict anything that is not needed.

TCP and UDP: registered post or a postcard

Before any service can use a port, the data has to be carried, and two transport protocols do almost all of that carrying. TCP (Transmission Control Protocol) first sets up a connection, then numbers every piece of data, has the receiver confirm what arrived, and resends anything lost, so the data arrives complete and in order. UDP (User Datagram Protocol) skips all of that: it simply sends each piece and does not check whether it arrived.

TCP is like sending a document by registered post with an acknowledgement card: slower, but you know it got there. UDP is like dropping postcards in a postbox: quick and light, and if one goes missing, nobody is told. TCP suits anything that must be exact, such as a web page, an email or the monthly sales file. UDP suits small quick questions and live audio or video, where a late piece is useless anyway and it is better to skip it than to wait.

TCP: registered postSets up a connection firstNumbers and confirms each pieceResends what was lostComplete and in orderWeb pages, email, file uploadsUDP: postcardsNo setup, just sendsNo confirmation of deliveryLost pieces stay lostFast and lightweightDNS questions, video calls

Neither is better; they suit different jobs. TCP trades a little speed for certainty, UDP trades certainty for speed.

TCP's connection setup is called the three-way handshake. The client says "I would like to talk" (a message called SYN, short for synchronise), the server replies "fine, I am ready too" (SYN-ACK, adding acknowledge), and the client confirms (ACK). Only then does real data flow. The handshake also has a security side: because the server has to answer, a flood of fake "I would like to talk" messages can keep it busy, which is one way attackers try to overwhelm servers.

PhoneApp serverSYN: can we talk?1SYN-ACK: yes, ready2ACK: connected3Now the real request4

Three short messages set up the connection before any real data moves. UDP has no equivalent; it just starts sending.

UDP has a weakness worth knowing: since there is no handshake, nothing checks that a message really came from the address written on it. That makes a forged sender address easier to use with UDP, which is why the services built on it add their own checks.

Sort the Tulsi Health jobs below by which carrier suits them. Ask yourself one question for each: would a missing piece ruin the result, or is speed more important than perfection?

Four protocols you meet every day

On top of TCP and UDP sit the protocols for particular jobs. Four of them are behind almost everything Mrs. Gokhale does in the app.

Protocol Job Port Carried by
HTTP Fetch web pages and app data, in plain readable text 80 TCP
HTTPS The same, but encrypted and with the server's identity checked 443 TCP (newer versions can use UDP)
DNS Turn a name like tulsihealth.in into an IP address 53 Mostly UDP
DHCP Lend a device an IP address when it joins a network 67 and 68 UDP

HTTP (HyperText Transfer Protocol) is the language browsers and apps use to ask a server for pages and data, and to send back things like a filled-in form. It sends everything as plain text. Anyone who can see the traffic on the way, such as someone on the same café Wi-Fi or a compromised router, can read it and even change it. HTTPS is HTTP wrapped in encryption (a protocol called TLS). The data is scrambled so that only the phone and the server can read it, and the server must show a certificate, a digital identity document vouched for by a trusted issuer, proving it really is tulsihealth.in. The padlock in a browser means exactly those two things: the connection is encrypted, and it goes to the name in the address bar. It does not mean the site is honest. A scammer's lookalike site such as tulsihea1th.in can have a padlock too, because the padlock vouches for the name, and the name itself is the trick.

DNS (Domain Name System) is the internet's phone directory: you know the name, it tells you the number. When Mrs. Gokhale opens tulsihealth.in, her phone first asks a DNS server for that name's IP address. If an attacker can give her phone a false answer, she is sent to the wrong server while the address bar still shows the right name; this is one reason the HTTPS certificate check matters so much. DHCP, the service that lends addresses, has a matching weak spot: a rogue device pretending to be the store's DHCP service could hand out its own settings and quietly route traffic through itself. Business-grade switches can be set to allow DHCP answers only from the real router.

Which windows should stay open?

Neha has a list of the ports that answer on the Tulsi Health cloud server and one billing laptop. Decide for each one whether it should stay open to the whole internet or be closed or limited to staff.

Follow your curiosity.

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