How to get active connections on a particular port in Linux ?

Here we will look how to get active connections on a particular port in Linux.

The active connections have a state “ESTABLISHED” when we look at the netstat output.

We can look the established connections via the command netstat and grepping established status.

I. NETSTAT Command
In netstat, we can grep established with particular port number.

[root@ngelinux ~]# netstat -anp | grep :22 | grep ESTABLISHED
tcp        0      0 172.21.49.239:22        172.21.49.169:59940     ESTABLISHED 6780/sshd: root@pts 
tcp        0      0 172.21.49.239:22        172.21.49.169:56893     ESTABLISHED 4307/sshd: root@pts 
[root@ngelinux ~]# 

II. LSOF Command
With lsof command, we can view the connections established i.e. active connections using below command.

$ lsof -i -P -n | grep ESTAB | grep :443
firefox   1819 saket   38u  IPv4 0xdf0727d5ef06bd35      0t0  TCP 17.168.63.98:52521->216.58.196.163:443 (ESTABLISHED)
firefox   1819 saket   39u  IPv4 0xdf0727d5eed613e5      0t0  TCP 17.168.63.98:52533->74.125.68.189:443 (ESTABLISHED)
firefox   1819 saket   40u  IPv4 0xdf0727d5eed1d275      0t0  TCP 17.168.63.98:52869->216.58.196.174:443 (ESTABLISHED)
firefox   1819 saket   89u  IPv4 0xdf0727d5e9e29a55      0t0  TCP 17.168.63.98:52853->173.241.248.143:443 (ESTABLISHED)
firefox   1819 saket   90u  IPv4 0xdf0727d5e9e17105      0t0  TCP 17.168.63.98:52779->192.0.78.23:443 (ESTABLISHED)
firefox   1819 saket   92u  IPv4 0xdf0727d5eed1ad35      0t0  TCP 17.168.63.98:52861->172.217.163.174:443 (ESTABLISHED)
firefox   1819 saket   94u  IPv4 0xdf0727d5eed1e515      0t0  TCP 17.168.63.98:52819->172.217.166.110:443 (ESTABLISHED)
firefox   1819 saket   96u  IPv4 0xdf0727d5eed65515      0t0  TCP 17.168.63.98:52666->172.217.26.162:443 (ESTABLISHED)
firefox   1819 saket  103u  IPv4 0xdf0727d5eed63925      0t0  TCP 17.168.63.98:52675->172.217.163.34:443 (ESTABLISHED)
firefox   1819 saket  117u  IPv4 0xdf0727d5efd56105      0t0  TCP 17.168.63.98:52671->172.217.26.196:443 (ESTABLISHED)
firefox   1819 saket  121u  IPv4 0xdf0727d5e51c27b5      0t0  TCP 17.168.63.98:52876->192.0.76.3:443 (ESTABLISHED)
firefox   1819 saket  122u  IPv4 0xdf0727d5ed3a4e65      0t0  TCP 17.168.63.98:52834->104.20.186.5:443 (ESTABLISHED)
firefox   1819 saket  124u  IPv4 0xdf0727d5ebcf57b5      0t0  TCP 17.168.63.98:52817->172.217.163.163:443 (ESTABLISHED)
firefox   1819 saket  127u  IPv4 0xdf0727d5ead29fd5      0t0  TCP 17.168.63.98:52851->172.217.163.198:443 (ESTABLISHED)
firefox   1819 saket  130u  IPv4 0xdf0727d5eed3cd35      0t0  TCP 17.168.63.98:52372->198.252.206.25:443 (ESTABLISHED)
firefox   1819 saket  146u  IPv4 0xdf0727d5eed1b685      0t0  TCP 17.168.63.98:50063->52.42.195.146:443 (ESTABLISHED)
firefox   1819 saket  152u  IPv4 0xdf0727d5ed3a6a55      0t0  TCP 17.168.63.98:52879->52.27.55.66:443 (ESTABLISHED)
firefox   1819 saket  173u  IPv4 0xdf0727d5eed3f275      0t0  TCP 17.168.63.98:52821->216.58.197.66:443 (ESTABLISHED)
firefox   1819 saket  177u  IPv4 0xdf0727d5eed65e65      0t0  TCP 17.168.63.98:52823->216.58.197.66:443 (ESTABLISHED)
firefox   1819 saket  185u  IPv4 0xdf0727d5e51befd5      0t0  TCP 17.168.63.98:52824->172.217.167.129:443 (ESTABLISHED)
firefox   1819 saket  199u  IPv4 0xdf0727d5e9e17a55      0t0  TCP 17.168.63.98:52847->216.58.200.131:443 (ESTABLISHED)
firefox   1819 saket  208u  IPv4 0xdf0727d5ead29685      0t0  TCP 17.168.63.98:52757->216.58.197.37:443 (ESTABLISHED)
firefox   1819 saket  217u  IPv4 0xdf0727d5eed1dbc5      0t0  TCP 17.168.63.98:52716->172.217.167.138:443 (ESTABLISHED)
com.apple 2350 saket    5u  IPv4 0xdf0727d5eed61d35      0t0  TCP 17.168.63.98:52471->17.34.83.69:443 (ESTABLISHED)
helpd     2948 saket    9u  IPv4 0xdf0727d5eed1bfd5      0t0  TCP 17.168.63.98:52909->23.61.90.107:443 (ESTABLISHED)
helpd     2948 saket   12u  IPv4 0xdf0727d5ead283e5      0t0  TCP 17.168.63.98:52910->23.61.91.176:443 (ESTABLISHED)
helpd     2948 saket   13u  IPv4 0xdf0727d5ead2ea55      0t0  TCP 17.168.63.98:52911->23.61.91.176:443 (ESTABLISHED)
helpd     2948 saket   14u  IPv4 0xdf0727d5ed3a4515      0t0  TCP 17.168.63.98:52912->23.61.91.176:443 (ESTABLISHED)
helpd     2948 saket   15u  IPv4 0xdf0727d5ebcf6105      0t0  TCP 17.168.63.98:52913->23.61.91.176:443 (ESTABLISHED)
ngelinux:~ saket$ 
0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments