Back to course

72. Checking Open Ports and Connections (`ss` and `netstat`)

Linux Basics: From Zero to CLI Hero

Analyzing Network Sockets

To ensure a server application (like Apache or SSH) is running and listening for connections, you check its network sockets and open ports.

The ss Command (Socket Statistics)

ss is the modern, faster replacement for netstat.

Common options:

  • -l: Display listening sockets.
  • -t: TCP connections.
  • -u: UDP connections.
  • -n: Numeric output (don't resolve hostname/port names).
  • -p: Show the process using the socket.

Example: Show all listening TCP sockets and the processes using them:

bash $ sudo ss -ltnp Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port Process tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* users:(("sshd",pid=1001,fd=3)) tcp LISTEN 0 128 127.0.0.1:631 0.0.0.0:* users:(("cupsd",pid=1002,fd=12))

This output confirms that sshd (SSH server) is listening on port 22.