List Network Ports on Linux Based Operating Systems =================================================== Author: Momchil Ivanov Date : 2021.03.25 Introduction ------------ This article describes different methods on how to list network ports on Linux based operating systems. Using netstat ------------- List all sockets: $ netstat -na List all TCP sockets: $ netstat -tna List all listening TCP sockets: $ netstat -tnl List all listening TCP and UDP sockets: $ netstat -tnlu To list all listening TCP and UDP sockets and the corresponding processes holding the socket: $ netstat -tnlpu List additional information: $ netstat -tnlpe Using ss -------- List all TCP sockets: $ ss -nta List all listening TCP sockets: $ ss -lnt List all listening TCP and UDP sockets: $ ss -lntu List all listening TCP and UDP sockets and the corresponding processes holding the sockets: $ ss -lntup Using lsof ---------- List all sockets: $ lsof -i List all listening TCP sockets (needs root): # lsof -iTCP -sTCP:LISTEN -n -P List all listening TCP sockets over IPv4 (needs root): # lsof -i4TCP -sTCP:LISTEN -n -P