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.
आता पॅकेट बरोबर मशीनपर्यंत पोहोचला, पण त्या मशीनवर कोणता प्रोग्राम उत्तर देईल? बघा, हे काम पोर्टचं आहे. Mauli Dairy च्या एकाच EC2 वर Nginx (80), SSH (22) आणि MySQL (3306) एकाच वेळी चालू शकतात, कारण प्रत्येक जण वेगळ्या पोर्टवर ऐकतो.
अब पैकेट सही मशीन तक पहुँच गया, लेकिन उस मशीन पर कौन सा प्रोग्राम जवाब देगा? देखो, ये काम पोर्ट का है. Mauli Dairy के एक ही EC2 पर Nginx (80), SSH (22) और MySQL (3306) एक साथ चल सकते हैं, क्योंकि हर एक अलग पोर्ट पर सुनता है.
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.
Ravindra Bagale's Tip – मराठी
बरेच students app 3000 किंवा 5000 port वर चालवतात आणि मग security group मध्ये 3000 सगळ्यांसाठी उघडा ठेवतात. असं करू नका! App 127.0.0.1 वर ठेवा, समोर Nginx 80/443 वर ठेवा, आणि security group मध्ये फक्त 22 (My IP), 80 आणि 443. Database चा 3306 तर कधीच 0.0.0.0/0 ला नाही.
Ravindra Bagale's Tip – हिंदी
बहुत से students app को 3000 या 5000 port पर चलाते हैं और फिर security group में 3000 सबके लिए खोल देते हैं. ऐसा मत करो! App को 127.0.0.1 पर रखो, सामने Nginx को 80/443 पर रखो, और security group में सिर्फ़ 22 (My IP), 80 और 443. Database का 3306 तो कभी भी 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.