The ss (Socket Statistics) command is a powerful utility in Linux used to display detailed information about network connections. It is a faster and more feature-rich alternative to the older netstat command. This guide explores the usage of ss, its options, and practical examples for managing network connections effectively.

If you’re looking for a reliable and high-performance hosting solution, Ava Hosting offers Linux VPS hosting with optimized network connectivity, making it an excellent choice for developers and system administrators who need stable and fast remote access.

1. Basic Usage

To display all active connections, simply run:

ss

This command shows a summary of all established connections, including their states and addresses.

2. Display Listening Ports

To view listening ports, use:

ss -l

This helps in identifying which services are currently listening for incoming connections.

3. Show TCP Connections

To filter only TCP connections, run:

ss -t

To view only listening TCP connections, use:

ss -lt

4. Show UDP Connections

To display UDP connections:

ss -u

To filter only listening UDP connections:

ss -lu

5. Show Connections by Process

To see which processes are associated with network connections, run:

ss -p

This is useful for troubleshooting applications using network resources.

6. Show IPv4 and IPv6 Connections

To display only IPv4 connections:

ss -4

For IPv6 connections:

ss -6

7. Show Detailed Information

For an in-depth view of all network sockets, use:

ss -s

This provides an overview of network socket statistics, including established, listening, and closed connections.

8. Filter Connections by Port

To check which connections are using a specific port, for example, port 80:

ss -at '( dport = :80 or sport = :80 )'

This is useful for monitoring web server traffic.

9. Monitor Real-Time Network Connections

For a continuously updating view of network activity, combine watch with ss:

watch ss -tulnp

This command refreshes every two seconds, displaying active connections, listening ports, and related processes.

Conclusion

The ss command is an essential tool for network monitoring and troubleshooting in Linux. It provides a faster and more detailed alternative to netstat, helping users analyze active connections, listening ports, and associated processes. Mastering ss can significantly enhance your network administration skills.