
{{ $('Map tags to IDs').item.json.title }}
How to Check Listening Ports with lsof
In Linux, the lsof
command (List Open Files) is a powerful utility that provides information about files opened by processes, including listening network ports. Monitoring listening ports is crucial for network security and management. This tutorial will guide you through using lsof
to check active listening ports.
1. Installing lsof
Most Linux distributions come with lsof
pre-installed. You can verify its availability by running:
lsof -v
If it is not installed, you can install it using:
- For Ubuntu:
sudo apt update sudo apt install lsof
- For CentOS:
sudo yum install lsof
2. Checking Listening Ports
To view all processes that are listening on network ports, use the following command:
sudo lsof -i -n -P | grep LISTEN
Here’s a breakdown of the options used:
- -i: Shows network connections.
- -n: Displays numerical addresses instead of resolving hostnames.
- -P: Displays port numbers instead of service names.
The output will look similar to this:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
sshd 1234 root 3u IPv4 123456 0t0 TCP *:22 (LISTEN)
3. Filtering by Specific Ports
If you want to check if a specific port is listening, you can use:
sudo lsof -i :80
This displays any processes listening on port 80.
4. Checking All Network Connections
To view all current network connections, whether listening or established, run:
sudo lsof -i -n -P
This will show a complete list of all open network connections on the system.
5. Conclusion
By following this tutorial, you have learned how to use the lsof
command to check listening ports in Linux. Monitoring active listening ports is essential for network security and troubleshooting. Continue to explore other options and capabilities of lsof
to further enhance your Linux networking skills!