Networking — Port, Protocol, Firewall

লেসন ৫ / ৩৮

📡 TCP vs UDP

  • TCP — reliable। HTTP, SSH, DB।
  • UDP — fast, no guarantee। DNS, video, gaming।

🚪 Common Ports

22    SSH
25    SMTP
53    DNS
80    HTTP
443   HTTPS
3306  MySQL
5432  PostgreSQL
6379  Redis
27017 MongoDB
3000  Node.js dev
8000  Django dev

🛡️ UFW Firewall

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp
sudo ufw allow 80,443/tcp
sudo ufw allow from 10.0.0.0/24 to any port 3306
sudo ufw enable
sudo ufw status verbose
sudo ufw delete allow 80

🌐 NAT

One Public IP → multiple Private IP। Home router এ এটাই হয়।

🏠 IP Ranges

Public:    Internet routable
Private:   10.0.0.0/8
           172.16.0.0/12
           192.168.0.0/16
Loopback:  127.0.0.1

🔍 Debug Commands

ss -tulnp                # listening ports
lsof -i :80              # who is on 80
nmap -sV server.com      # port scan (own only!)
nc -zv example.com 443   # test port open
tcpdump -i eth0 port 80  # packet capture

🛡️ Production Checklist

  • SSH key only, port 22 changed
  • DB port — internal only
  • Redis password set, never public
  • UFW deny default
  • Cloud security group layered
  • Fail2ban for SSH

🎓 মূল কথা ⭐

Default deny, allow specific। DB port public = guaranteed hack। UFW + Cloud firewall = layered defense।