Show active ports on Linux

netstat is a tool on Linux, that displays various information about the network including statistics, active connections etc. We will use it to identify active ports (connections).

netstat is shipped by default with Ubuntu, no extra installation is required.

 sudo netstat -tlpn

With the flag t netstat will only return TCP connections. (TCP and TCP6)

With the flag l netstat will show only listening sockets (active connections used to act as server).

With the flag p netstat will also show the PID and name of the program to which each socket belongs. If you run netstat without the required permission (e.g. skipping the sudo, it will just add an empty PID/Program column to its output)

With the flag n netstat will show numerical addresses instead of trying to determine symbolic host, port or user names.