How to check if a port is open in Linux

> How to check if a port is open on Linux

Check if port is open in Linux

Linux systems have many ports. In most cases, you will need to determine which ports are open on your system’s network interface. In this tutorial, you will learn how to check if a port is open on Linux.

Quick note

You can check for open Linux ports using utilities such as: netstat, ss, lsof And nmap Such. In the latest version of Linux systems, ss Commands are mainly used. Run a command to check if the port is open on Linux.

Check open ports using nmap command:

sudo nmap -sTU -O ENTER-IP-ADDRESS

Use the following ss Commands for the latest version of Linux:

ss -tulwn

An example is shown below nmap And lsof command.

sudo lsof -i -P -n | grep LISTEN
sudo netstat -tulpn | grep LISTEN

1. Check open ports using nmap command

of nmap Powerful network scanning tool used for penetration testing and security auditing. Used for scanning single hosts and large networks.

Basic syntax for checking open ports nmap Shown below.

sudo nmap -sTU -p- ENTER_IP_ADDRESS

Less than nmap The command displays all open ports for TCP and UDP addressing the local host (127.0.0.1).

sudo nmap -sTU -p- 127.0.0.1

The output looks like this:

How to check if a port is open in Linux

2. Check open ports lsof command

To check for open ports lsof Command with grep With commands, you can enter the following commands in Terminal:

sudo lsof -i -P -n | grep LISTEN

The output looks like this:

How to check if a port is open in Linux

3. Check open ports ss command

of ss The command is also used to determine which listening port is open on Linux. As netstat The command will be obsolete for a while. You must use ss Command instead:

Less than ss The command displays all listening open ports on the system.

sudo ss -tulwn

The output looks like this:

How to check if a port is open in Linux

4. Check the listening port netstat command

You can determine which ports are open on your system using the following command: netstat command. To do so you can enter following command:

netstat -tulpn | grep LISTEN

The output looks like this:

How to check if a port is open in Linux

note: netstat Some system commands are obsolete for some time. Can be used ss The command given at the point above.

Conclusion

You learned how to check if a port is open on Linux. If you have any questions, don’t forget to comment below.

Sidebar