Ss Command Guide
Understanding the Ss Command
The ss command is a powerful utility in Linux for
investigating network sockets. It's a modern replacement for the
older netstat command, offering faster performance and
more detailed information. This tool is essential for network
administrators, developers, and anyone needing to diagnose network
connectivity issues or monitor network activity on a system. It
allows you to view, filter, and analyze various types of sockets,
including TCP, UDP, and Unix domain sockets, and can display
associated processes.
Ss Command Options and Usage
The ss command provides a wide array of options to
tailor your output. Here are some of the most commonly used flags:
-
-4/-6: List only IPv4 or IPv6 sockets, respectively. -
-n: Display numeric addresses and port numbers instead of trying to resolve hostnames and service names. This speeds up the command and avoids DNS lookups. -l: Show only listening sockets.-u: Display UDP sockets.-t: Display TCP sockets.-x: Display Unix domain sockets.-
-p: Show the process(es) that are using the socket. This is crucial for identifying which application is responsible for a particular network connection.
Practical Ss Command Examples
Here are some practical examples demonstrating how to use the
ss command effectively:
---
tags: [ networking ]
---
Args
-4/-6 list ipv4/ipv6 sockets
-n numeric addresses instead of hostnames
-l list listing sockets
-u/-t/-x list udp/tcp/unix sockets
-p Show process(es) that using socket
# show all listening tcp sockets including the corresponding process
ss -tlp
# show all sockets connecting to 192.168.2.1 on port 80
ss -t dst 192.168.2.1:80
# show all ssh related connection
ss -t state established '( dport = :ssh or sport = :ssh )'
Advanced Ss Command Filtering
The ss command allows for sophisticated filtering based
on various criteria such as destination address, port, and
connection state. This enables precise analysis of network traffic.
For instance, you can filter by destination IP and port, or by
specific connection states like 'established'.
Further Resources
For more in-depth information and advanced usage, consult the official documentation: