find active connections port ubuntu

Linux Show Active Connections on Port

Linux allows you to run different kinds of servers that listen to various ports for incoming connections. Every successful connection creates a socket (combination of ip address and port). System administrators often need to keep track of active connections to port in Linux. In this article, we will learn how to show active connections on port. There are many tools available for this purpose. We will use ss tool and netstat tools for this purpose.

Linux Show Active Connections on Port

Both ss and netstat tools give you statistics of open port connections in your system. They are already present by default on most Linux systems. You can run them with following commands.

# ss
OR
# netstat

Both the above commands give a list of all connections on your system. If you want to show active connections on specific port such as port 80 (HTTP) or port 443 (HTTPS), you can use the following commands. In this case, we will filter the output of ss and netstat commands by sport value.

# ss -o state established '( sport = :http or sport = :https )'
OR
# netstat -o state established '( sport = :http or sport = :https )'

Alternatively, you can filter the output of ss and netstat commands by src column.

# ss -tn src :80 or src :443
OR
# netstat -tn src :80 or src :443

Similarly, you can show active connections to specific ports by replacing 80 and 443 in above commands with the desired port numbers.

In this article, we have learnt how to show active connections in Linux. You can use these steps on all Linux systems.

Also read:

How to Install CSF in CentOS & Ubuntu
How to Install Visual Studio Code in Ubuntu
How to Evaluate Expression in Shell Script
What Does ${} and $() mean in Shell Script
How to Run C Program in Linux

Leave a Reply

Your email address will not be published. Required fields are marked *