Terminus
List Open Ports in Linux

List Open Ports in Linux

[#list-open-ports] The short answer [#list-open-ports]

In Linux, to get the list of open ports on your local machine, you can use the [.inline-code]netstat[.inline-code] command as follows:

$ netstat -tuln

Where:

  • The [.inline-code]-t[.inline-code] flag is used to show TCP ports.
  • The [.inline-code]-u[.inline-code] flag is used to show UDP ports.
  • The [.inline-code]-l[.inline-code] flag is used to only show open ports.
  • The [.inline-code]-n[.inline-code] flag is used to show IP addresses and port numbers.

For example:

Proto   Recv-Q   Send-Q   Local Address    Foreign Address   State
tcp       0             0             0.0.0.0:22           0.0.0.0:*                LISTEN
tcp       0             0             127.0.0.1:5432   0.0.0.0:*                LISTEN
udp      0             0             0.0.0.0:68           0.0.0.0:*

Note that the [.inline-code]netstat[.inline-code] command is available in the [.inline-code]net-tools[.inline-code] package.

[#easily-recall-commands-with-ai] Easily retrieve these commands using Warp's AI Command Suggestions feature [#easily-recall-commands-with-ai]

If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Suggestions feature:

Entering [.inline-code]linux list open ports[.inline-code] in the AI Command Suggestions will prompt a [.inline-code]netstat[.inline-code] command that can then quickly be inserted into your shell by doing [.inline-code]CMD+ENTER[.inline-code].