Monitor Network Connections on CentOS Using the ss Command

The ss utility, part of the iproute2 package, is a powerful tool for reviewing socket statistics. The name stands for “socket statistics” and allows administrators to view detailed information about sockets, including TCP, UDP, and Unix domain sockets.

For system administrators, analyzing these statistics can help diagnose and resolve potential network connectivity problems.

Unlike older tools like netstat, ss operates significantly faster, making it ideal for systems under heavy traffic. Because of this efficiency, ss is often preferred over netstat for real-time network monitoring.

Requirements

  • A CentOS 6.x 64-bit server instance
  • A user with sudo privileges

Installing ss (if not already available)

Most modern Linux distributions come with ss pre-installed. If it’s missing, you can install it along with its documentation on RPM-based systems using:

sudo yum install iproute iproute-doc

Common Usage Examples of ss

The following examples highlight typical ss commands. For a full list of options, use the help flag:

Display a Summary of Socket Usage

Show Listening IPv4 Sockets with Process Information

This is a combination of the following flags: -4, -n, -l, and -p.

Display IPv4 Sockets Only

Show Port Numbers Instead of Service Names

List Listening Sockets

Display Processes Using Sockets

View All Socket Connections

Filter by Socket Type

List TCP, UDP, RAW, or Unix domain sockets:

ss -at
ss -au
ss -ar
ss -ax

Find the Process on Port 22

Note: You must use the -n flag together with the port number (e.g., 22) to ensure accurate output.

Show Connections to a Specific Remote Host

Filter by Local Address and Port

View Help Options

or

Conclusion

The ss command is a versatile and efficient tool for real-time socket analysis on CentOS and other Linux systems. With its rapid performance and flexibility in filtering data, it is highly beneficial for system administrators managing modern, high-traffic servers. Mastering the various ss options can greatly enhance your ability to monitor and troubleshoot network activity effectively.

Source: vultr.com

Create a Free Account

Register now and get access to our Cloud Services.

Posts you might be interested in: