Ports and sockets
Concepts
- Port: 16-bit number used by TCP/UDP to demultiplex traffic
- Socket: (IP, port, protocol) endpoint
- A TCP connection is identified by the 5-tuple:
(src IP, src port, dst IP, dst port, protocol)
Common port ranges
- 0–1023: privileged/well-known
- 1024–49151: registered
- 49152–65535: ephemeral (client-side often uses these)
Inspect listening ports
Modern (ss):
ss -tulpn
ss -ltnp
ss -lunp
Legacy (netstat from net-tools):
Map ports to processes
sudo lsof -i -P -n | head
sudo lsof -iTCP -sTCP:LISTEN -P -n
Quick connectivity tests
curl -I http://127.0.0.1:8080
nc -vz 127.0.0.1 8080