Home Linux ServerLinux Fundementals 12 useful ss commands on Linux

12 useful ss commands on Linux

by
Published: Last Updated on
A+A-
Reset

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.

AZDIGI Tutorial
ss
Hoặc
sudo ss
    

Here is the information after I use the ss command on Linux.

ss-commands-on-Linux
List all connections when using 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.

AZDIGI Tutorial
ss -a
Hoặc
sudo ss -a
    

Here is the information after I use the ss -a command.

ss-commands-on-Linux
List Listening and Non-listening ports.

3. List Listening Sockets

To only show Listening Sockets, use the -l option as follows:

AZDIGI Tutorial
ss -l
Hoặc
sudo ss -l
    

Here is the information after I use the ss -l command.

ss-commands-on-Linux
List Listening Sockets.

4. List all TCP connections

To display all TCP connections, use the -t option as follows:

AZDIGI Tutorial
ss -t
Hoặc
sudo ss -t
    

Here is the information after I use the ss -t command.

ss-commands-on-Linux
List all TCP connections.

5. List all TCP connections in the Listening state

To display all TCP connections in the Listening state, use the -lt option as follows:

AZDIGI Tutorial
ss -lt
Hoặc
sudo ss -lt
    

Here is the information after I use the ss -lt command.

ss-commands-on-Linux
List all TCP connections in the Listening state.

6. List all UDP connections

To display all UDP connections, use the -u option as follows:

AZDIGI Tutorial
ss -u
Hoặc
sudo ss -u
    

Here is the information after I use the ss -u command.

ss-commands-on-Linux
List all UDP connections.

7. List all UDP connections in the Listening state

To display all UDP connections in the Listening state, use the -lu option as follows.

AZDIGI Tutorial
ss -lu
Hoặc
sudo ss -lu
    

Here is the information after I use the ss -lu command.

ss-commands-on-Linux
List all UDP connections in the Listening state.

8. Display the PID (Process ID) of Sockets

To display the process IDs related to socket connections, use the -p option as follows:

AZDIGI Tutorial
ss -p
Hoặc
sudo ss -p
    

Here is the information after I use the ss -p command.

ss-commands-on-Linux
Display the PID (Process ID) of Sockets.

9. Display Summary Statistics

To list summary statistics, use the -s option.

AZDIGI Tutorial
ss -s
Hoặc
sudo ss -s
    

Here is the information after I use the ss -s command.

ss-commands-on-Linux
Display summary statistics.

10. Display IPv4 and IPv6 Socket Connections

To list IPv4 and IPv6 socket connections, use the -4 option.

AZDIGI Tutorial
ss -4
Hoặc
sudo ss -4
    

Here is the information after I use the ss -4 command.

ss-commands-on-Linux
Display IPv4 and IPv6 Socket Connections.

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:

AZDIGI Tutorial
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:

ss-commands-on-Linux
Filter connections by Port 443.

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:

AZDIGI Tutorial
man ss
    
ss-commands-on-Linux
General ss command manual page on Linux.

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:

Đánh giá

Tham gia nhóm hỗ trợ Server - Hosting

Tham gia nhóm Hỗ trợ Server - Hosting & WordPress để cùng nhau hỏi đáp và hỗ trợ các vấn đề về WordPress, tối ưu máy chủ/server.

Tham gia ngay

Bài viết cùng chuyên mục

AZDIGI – Không chỉ là đơn vị hàng đầu trong lĩnh vực Web Hosting và Máy chủ, chúng tôi mong muốn mang lại những kiến thức bổ ích nhất và luôn cập nhật thường xuyên cho cộng đồng người đam mê thiết kế website, công nghệ,…

Vui lòng không sao chép nội dung nếu chưa xin phép. Designed and Developed by PenciDesign