List Open Ports in Linux
Razvan Ludosanu
Founder, learnbackend.dev
Updated: 7/11/2024
Published: 7/11/2024
The short answer
In Linux, to get the list of open ports on your local machine, you can use the netstat command as follows:
$ netstat -tuln
Run in Warp
Where:
- The -t flag is used to show TCP ports.
- The -u flag is used to show UDP ports.
- The -l flag is used to only show open ports.
- The -n 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:*
Run in Warp
Note that the netstat command is available in the net-tools package.
Easily retrieve these commands using Warp's AI Command Suggestions feature
If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Suggestions feature:
Entering linux list open ports in the AI Command Suggestions will prompt a netstat command that can then quickly be inserted into your shell by doing CMD+ENTER.
Written by
Razvan Ludosanu
Founder, learnbackend.dev
Filed Under
Related Articles
Count Files in Linux
Learn how to count files and folders contained in directories and subdirectories in Linux using the ls, find, and wc commands.
How to Check the Size of Folders in Linux
Learn how to output the size of directories and subdirectories in a human-readable format in Linux and macOS using the du command.
Linux Chmod Command
Understand how to use chmod to change the permissions of files and directories. See examples with various chmod options.
POST JSON Data With Curl
How to send valid HTTP POST requests with JSON data payloads using the curl command and how to avoid common syntax pitfalls. Also, how to solve the HTTP 405 error code.
Format Command Output In Linux
Learn how to filter and format the content of files and the output of commands in Linux using the awk command.
Create Groups In Linux
Learn how to manually and automatically create and list groups in Linux.
Switch Users In Linux
Learn how to switch between users, log in as another user, and execute commands as another user in Linux.
Remover Users in Linux
Learn how to remove local and remote user accounts and associated groups and files in Linux using the userdel and deluser commands.
Delete Files In Linux
Learn how to selectively delete files in Linux based on patterns and properties using the rm command.
Find Files In Linux
Learn how to find and filter files in Linux by owner, size, date, type and content using the find command.
Copy Files In Linux
Learn how to safely and recursively copy one or more files locally and remotely in Linux using the cp and scp command.
Create Files In Linux
Learn how to create regular files in Linux using command line interface commands like touch, echo, cat, printf, and in-terminal text editors like Vim.