I have a question for you: what happens if you have two TCP services running on one computer and you want to talk to one of them? How does the client/server model know what service you want to connect to? That's where port numbers come into play.
With TCP (and UDP, which we cover later), a port number is used to identify what service you want to talk to on the remote server. Let's look at an example.
When you request
https://upload.academy in your web browser, it knows you want to connect a remote system with the hostname
upload.academy (covered in DNS) via the protocol
HTTPS (explained later.) So the remote server is using the
HTTPS protocol to communicate with clients (your browser.)
HTTPS is a known protocol, your browser knows two things:
- It needs to connect using
- It needs to connect to port
A service like
HTTPS listens on a particular port -
443 - for new, inbound TCP connections. This is also called a "socket." So the webserver software creates a socket that is bound to port
443 using the TCP protocol. Once the connection is complete, the browser then uses the protocol
HTTPS to "talk" to the remote system. We covered this conversation in the overview of protocols.
Your browser will also use a "socket", locally, when communicating with the web server at
upload.academy, but the port number will be random. Unlike the web server which needs to listen on a fixed, known port (otherwise how would you know what to connect to?) your local client can use a random port number from a large range, picked at random. The client needs this port so that the networking stack in your kernel knows where to send the replies from reote web server.
There are literally thousands of known port numbers used by a whole variety of software suites, but there are just a handful you need to be aware of. I've listed them below.
| ||FTP (insecure protocol; don't use)|
| ||Secure SHell (SSH)|
| ||Simple Mail Transfer Protocol (SMTP); a.k.a the sending of email|
| ||Domain Name System (DNS); but it's actually used via UDP mostly|
| ||HyperText Transfer Protocol (HTTP); a.k.a "the web"|
| ||Post Office Protocol v3 (POP3); a.k.a the receiving of email|
| ||Internet Message Access Protocol (IMAP); the receiving of email|
| ||Border Gateway Protocol (BGP)|
| ||Lightweight Directory Access Protocol (LDAP)|
| ||HTTP Secure; a.k.a "the web" but encrypted/secure|
| ||SMTP over TLS/SSL; a.k.a the sending of email over encryption|
| ||Microsoft SQL Server|
| ||MySQL database|
| ||Windows Terminal Server (RDP)|
| ||PostgreSQL database|
And so, so many more. Review the complete list over at Wikipedia.
Just remember that you're not expected to remember them all. I'd argue you only really need to recognise the important ports you're going to see daily as a working system administrator in a Cloud environment:
- HTTP on
80and HTTPS on
- SSH on
- DNS on
And not so daily from an administrative perspective (or at all in some cases), but used heavy by everyone daily (minute by minute for some devices like mobile phones):
- SMTP on
- POP3 on
- IMAP on
Or put another way: email.
There are some special port ranges you should be aware of, as well as some rules with regards to what ports can be used by a process.
Well known port numbers range between
0 all the way through to
1023. These are the port numbers used for the most common services we'll come to know and understand throughout this course. These port numbers include everything above under "Common Ports" until port
1433/1434, non-inclusive. These are also known as privileged ports, and root level (or Administrator on Windows) access is requireds to bind a process to these port numbers.
49151 are considered "registered ports".
65535 are called "dynamic ports".