Ravindra BagaleCourses & study guides मराठी Track your progress

Chapter 1: Networking Fundamentals

1.3 Ports

In short: A port is a 16-bit number (0–65535) that identifies a specific process/service on a host.

Now the packet has reached the right machine – but which program on that machine will answer? Look, that is the job of the port. On a single EC2 of Mauli Dairy, Nginx (80), SSH (22) and MySQL (3306) can all run at the same time, because each one listens on a different port.

A port is a 16-bit number (0–65535) that identifies a specific process/service on a host. One server with one IP can run a web server (port 80), SSH (port 22) and MySQL (port 3306) at the same time because each listens on a different port. The combination IP:port (e.g. 13.233.10.25:443) is called a socket.

Range Name Meaning
0 – 1023 Well-known ports Reserved for standard services; need root to bind on Linux
1024 – 49151 Registered ports Used by applications (MySQL, MongoDB, dev servers)
49152 – 65535 Dynamic / ephemeral Temporary client-side ports chosen by the OS

Common ports you must remember

Port Protocol Service Where you will see it
20, 21 TCP FTP (data, control) Legacy file transfer (avoid; insecure)
22 TCP SSH / SCP / SFTP Logging in to EC2, copying files
23 TCP Telnet Legacy, insecure — never open
25 TCP SMTP Sending e-mail (AWS throttles port 25 by default)
53 UDP/TCP DNS Domain name lookups
67, 68 UDP DHCP Automatic IP assignment
80 TCP HTTP Websites (unencrypted)
110 / 143 TCP POP3 / IMAP Receiving e-mail
443 TCP HTTPS Websites with TLS/SSL
3000 TCP Node.js / React dev server Express apps, npm start
3306 TCP MySQL / MariaDB Database
3389 TCP RDP Windows Remote Desktop
4200 TCP Angular dev server ng serve
5000 TCP Flask dev server flask run
5432 TCP PostgreSQL Database
6379 TCP Redis Cache
8000 TCP Gunicorn / Django dev server Python apps
8080 TCP Alternate HTTP / Tomcat / Jenkins Java apps, proxies
27017 TCP MongoDB NoSQL database

Security rule of thumb

Only ports 22, 80 and 443 normally need to be open to the internet. Application ports (3000, 5000, 8080) should sit behind a reverse proxy (Nginx/Apache), and database ports (3306, 27017) should never be open to 0.0.0.0/0.

Ravindra Bagale's Tip

Many students run their app on port 3000 or 5000 and then open 3000 to everyone in the security group. Don't do this! Keep the app on 127.0.0.1, put Nginx in front on 80/443, and in the security group allow only 22 (My IP), 80 and 443. And never open the database's 3306 to 0.0.0.0/0.

Lab

Chala, tumchya Linux machine var sudo ss -tlnp chalva aani konte ports listen hot aahet te liha. Pratyek port samor service che naav liha – varchya table madhun (22 SSH, 80 HTTP ...) match kara. Kontahi port table madhe nasel tar ss chya shevatchya column madhe process che naav bagha.