How to Install and Use ss on Linux
How to Install and Use ss on Linux
ss is a powerful networking utility that replaces the older netstat command. It provides detailed information about socket connections, network traffic, and more, making it essential for system administrators and network engineers. In this guide, we will explore how to install and use ss on Linux.
Installation
The ss command is part of the iproute2 package, which is pre-installed on most modern Linux distributions. However, if it’s not available on your system, follow the installation instructions below.
On Ubuntu/Debian
Update the package list:
sudo apt update
Install iproute2 (if necessary):
sudo apt install iproute2
On Arch Linux
Install iproute2 using pacman:
sudo pacman -S iproute2
On Fedora
Install iproute2 with dnf:
sudo dnf install iproute
Using ss
Once installed, you can use ss to gather information about network connections, socket statistics, and much more.
Viewing Active Connections
To list all active TCP, UDP, and other socket connections, simply run:
ss
Viewing Listening Sockets
If you want to see only the listening sockets, use the -l option:
ss -l
Viewing TCP Connections
To filter and display only TCP connections:
ss -t
You can also use -ta to view both established and listening TCP connections:
ss -ta
Viewing UDP Connections
To view only UDP connections:
ss -u
Viewing Connection Details
To display detailed information about all connections, including the process ID (PID) of each connection, use:
ss -p
Filtering by Port or Address
To filter results by a specific port, such as port 80, use:
ss -tuln sport = :80
To filter connections by a remote IP address, for example, 192.168.1.10:
ss dst 192.168.1.10
Monitoring Real-Time Connections
If you need to monitor active connections in real time, the watch command can be used with ss:
watch ss -t
This will refresh the output of ss every two seconds, allowing you to monitor changes dynamically.
Conclusion
The ss command is a versatile tool for managing and analyzing network connections on Linux systems. Whether you’re troubleshooting network issues or simply monitoring traffic, ss offers a fast and powerful way to get the information you need.