Whether you are troubleshooting network connectivity issues or configuring a firewall, one of the first things you should check is what ports are open on your system. In this article, we will show you how to check Linux open or network listening ports. Keep along with us!

What is an open port?

An open port is a network including listening software, which hackers or attackers can use to exploit a vulnerability or perform any other type of cyberattack on your network privacy.

How to check the Linux open ports using the “netstat” command?

Netstat command helps you to identify open ports on a system. You will also see the IP addresses of other systems connected to your network. 

Therefore, if your system is connected to a Linux tunnelled network, you will be able to see not only the open ports but the listening of the connections on your system.

You can use this command to detect and identify Trojans' backdoors since they connect outside the system to transfer the data. You can use a command like “netstat” to determine which external IP your system is connecting.

It is a very good troubleshooting tool, which needs the –an flag to be used. This flag will help you list all the ports listening to your system. 

To scan the network listening ports using the “netstat”, you should follow these steps:

  • Go to your terminal or press Ctrl + Alt + T
  • Type in the following syntax in your command line:

$ netstat –antplF

  • Now, you can find a column that says local address, and unless the local address section, you find the open ports you are looking for.

How to check the Linux open ports using the “nmap” tool?

Nmap (Network Mapper) is a command-line networking tool that you can use to scan devices and create a network map on your system.

To scan the network listening ports using the “nmap”, you should follow these steps:

  • Press Ctrl + Alt + T to open the terminal.
  • Type in the following command to install nmap tool:

$ sudo apt-get install nmap

  • Hit Enter.
  • Type your password.
  • Check if it is installed by typing in the following syntax:

$ nmap 

  • When you have ensured the required utility had been installed perfectly, you can open another page in your terminal and scan the open ports by running the following command:

$ nmap –open [IP address of your PC or the IP address you want to check for open ports]

  • Now, you will find the open ports.

What is the difference between “netstat” and “nmap” functionality?

Comparing these commands, you will see “netstat” shows only the ports that can be accessed locally or the port that can be accessed from your local serial machine.

However, when using “nmap” open command, it only shows the ports that can be accessed from outside. You can do a lot with these two commands; we only showed you a few!

How to check the Linux open ports using the “netcat”?

If you have ever needed to scan some ports, but you cannot install “nmap” or it is not installed in the system, you might be able to do it with “netcat”. 

This is not going to give you a full “nmap” experience, but it will give you the basic port scanning functionality that you are looking for.

So, what we need to do is to create a bash for loop just right on the terminal there using the following command:

$ for i in $(seq 1 65535); do nc –nvz –w 1 [Ip address of the local host that you want to scan] $i 2>&1; done

Now, you are going to pipe this through “grep” in the following order:

| grep –v “refused”

This means you want to do the inverse process and ask the system to grab anything other than refused. Now, you can hit Enter and wait to see the list of open ports.

The Bottom Line

Here, you learned about open ports and different methods to check them out on your system. Please, feel free to leave us your feedback and comments. Do not hesitate to ask us if you have questions about Linux open ports and the scanning process. When you buy linux vps, it is important to consider factors such as the level of technical support provided, the security measures in place, and the cost of the hosting plan. we offer you best services. Good luck!

People also read: