HostOnNet Blog


List all Open Ports

To list all open ports, run

lsof -i

Example

[root@vpn ~]# lsof -i
COMMAND   PID   USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
chronyd   465 chrony    1u  IPv4  12046      0t0  UDP vpn.rallyround.co:323 
chronyd   465 chrony    2u  IPv6  12047      0t0  UDP vpn.rallyround.co:323 
master   1320   root   13u  IPv4  14822      0t0  TCP vpn.rallyround.co:smtp (LISTEN)
master   1320   root   14u  IPv6  14823      0t0  TCP vpn.rallyround.co:smtp (LISTEN)
sshd     8603   root    3u  IPv4 102950      0t0  TCP vpn.rallyround.co:ssh->c-73-136-44-38.hsd1.tx.comcast.net:50157 (ESTABLISHED)
sshd     8669 master    3u  IPv4 102950      0t0  TCP vpn.rallyround.co:ssh->c-73-136-44-38.hsd1.tx.comcast.net:50157 (ESTABLISHED)
sshd     8951   root    3u  IPv4 104598      0t0  TCP vpn.rallyround.co:ssh->c-73-136-44-38.hsd1.tx.comcast.net:51189 (ESTABLISHED)
sshd     8954 master    3u  IPv4 104598      0t0  TCP vpn.rallyround.co:ssh->c-73-136-44-38.hsd1.tx.comcast.net:51189 (ESTABLISHED)
sshd    17110   root    3u  IPv4 223055      0t0  TCP *:ssh (LISTEN)
sshd    17110   root    4u  IPv6 223057      0t0  TCP *:ssh (LISTEN)
sshd    17433   root    3u  IPv4 227293      0t0  TCP vpn.rallyround.co:ssh->59.98.136.146:39150 (ESTABLISHED)
openvpn 19917 nobody    5u  IPv4 256592      0t0  UDP *:openvpn 
sshd    19960   root    3u  IPv4 257107      0t0  TCP vpn.rallyround.co:ssh->59.98.136.146:44660 (ESTABLISHED)
[root@vpn ~]#

You can also use netstat -an to list all open ports

[root@vpn ~]# netstat -an | grep LISTEN | grep -v unix
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:25            0.0.0.0:*               LISTEN     
tcp6       0      0 :::22                   :::*                    LISTEN     
tcp6       0      0 ::1:25                  :::*                    LISTEN     
[root@vpn ~]# 

Posted in Linux