You are currently viewing How to Check for Open Ports in Linux

How to Check for Open Ports in Linux

Linux is a powerful kernel with a powerful terminal and command line interface. This interfaces provides users with a wide variety of tools and commands to check for open ports.  Ports are like communication endpoints, allowing data to flow in and out of the system. Whether you are troubleshooting connectivity issues or ensuring the security of the system, everyone needs to know how to check for open ports. Let me show some of the methods i know, 

Using the netstat Command

The netstat command is a simple tool for examining network connections and open ports on a Linux system. To list all open ports, simply execute

Bash
netstat -tulpn

This command will also display a list of all open ports along with their corresponding services and their status. To see the process names you might need sudo access, please keep that in mind. 

Using the ss Command

The ss command is an alternative to that of the netstat and provides more detailed information. To display open ports, use

Bash
ss -tulpn

Similar to netstat, this command also shows the list of open ports, along with their status, protocol, and the process that owns each port and similarly sudo might be needed. 

Using the nmap Tool

Nmap, short for Network Mapper, is an open-source tool for network exploration and security auditing used to scan open ports on a specific IP address or range, the command to do that is,

Bash
nmap [target]

Nmap will conduct a comprehensive scan and present a detailed report of open ports, services, and potential vulnerabilities.

Using Telnet

Telnet can be used to check whether a specific port is open on a remote server. Execute

Bash
telnet [hostname or IP] [port]

If the connection is successful, the port is open; otherwise, an error message will be displayed.

Checking with lsof

The lsof command (list open files) can be employed to display open network connections and associated processes. To check for open ports

Bash
lsof -i

This command reveals the processes using network connections, aiding in pinpointing the source of open ports.

Using the Firewall

Linux systems often employ firewalls to control incoming and outgoing network traffic. The iptables command is a powerful tool for configuring the firewall. To display open ports, run

Bash
iptables -L

Additionally, you can use ufw (Uncomplicated Firewall) on Ubuntu-based systems

Bash
ufw status

This command provides a straightforward overview of open ports and their corresponding services.

Checking with /proc Filesystem:

Linux provides a virtual filesystem, /proc/, which contains information about processes and system configurations. To inspect open ports, navigate to

Bash
cat /proc/net/tcp

This command displays information about TCP connections, including open ports.

Using the lsof and grep Combination

Combine lsof with grep to filter specific information. For instance, to find processes using a specific port (e.g., 80), use

Bash
lsof -i :80 | grep LISTEN

This command isolates processes listening on port 80.

Conclusion

We all have been there when there is a need to check but we have forgotten the command to do it. I hope this helps in those times and show you the open ports and let you pin on the engineer who left a vulnerability in the system.

Leave a Reply