Nội dung
In this tutorial, AZDIGI will list 12 useful ss commands on Linux that any administrator should know.
I. Introduction
The ss command on Linux is a tool used to display information related to network sockets on the Linux system. This tool displays more detailed information than the netstat command is usually used to display active network socket connections.
In this guide, AZDIGI will delve into how the ss command on Linux can be used to display different socket connection information on Linux.
II. Commonly used ss commands on Linux
1. List all connections
The basic ss command on Linux has no options and simply lists all connections regardless of their state.
ss Hoặc sudo ss
Here is the information after I use the ss
command on Linux.
2. List Listening and Non-listening ports
You can access both Listening and Non-listening ports by using the -a
option as shown below.
ss -a Hoặc sudo ss -a
Here is the information after I use the ss -a
command.
3. List Listening Sockets
To only show Listening Sockets, use the -l
option as follows:
ss -l Hoặc sudo ss -l
Here is the information after I use the ss -l
command.
4. List all TCP connections
To display all TCP connections, use the -t
option as follows:
ss -t Hoặc sudo ss -t
Here is the information after I use the ss -t
command.
5. List all TCP connections in the Listening state
To display all TCP connections in the Listening state, use the -lt
option as follows:
ss -lt Hoặc sudo ss -lt
Here is the information after I use the ss -lt
command.
6. List all UDP connections
To display all UDP connections, use the -u
option as follows:
ss -u Hoặc sudo ss -u
Here is the information after I use the ss -u
command.
7. List all UDP connections in the Listening state
To display all UDP connections in the Listening state, use the -lu
option as follows.
ss -lu Hoặc sudo ss -lu
Here is the information after I use the ss -lu
command.
8. Display the PID (Process ID) of Sockets
To display the process IDs related to socket connections, use the -p
option as follows:
ss -p Hoặc sudo ss -p
Here is the information after I use the ss -p
command.
9. Display Summary Statistics
To list summary statistics, use the -s
option.
ss -s Hoặc sudo ss -s
Here is the information after I use the ss -s
command.
10. Display IPv4 and IPv6 Socket Connections
To list IPv4 and IPv6 socket connections, use the -4
option.
ss -4 Hoặc sudo ss -4
Here is the information after I use the ss -4
command.
11. Filter Connections by Port Number
The ss command on Linux also allows you to filter by port number. For example, to display all socket connections with an https port, run the following command:
ss -at '( dport = :443 or sport = :443 )' Hoặc sudo ss -at '( dport = :443 or sport = :443 )'
Here is the result when I run the command:
So we have gone through 11 commonly used ss commands on Linux. If you want to learn more, you can use the following command to see more:
man ss
III. Summary
So we have gone through 11 commonly used ss commands on Linux. Hopefully, this article will make your system administration work much easier.
See more useful articles about Linux VPS at the following link:
If you need assistance, you can contact support in the ways below:
- Hotline 247: 028 888 24768 (Ext 0)
- Ticket/Email: You use the email to register for the service and send it directly to: support@azdigi.com .