Posted on
Command Line Interface

Three Ways To Learn What Is Listening On a Port

Author
  • User
    Linux Bash
    Posts by this author
    Posts by this author

Here are three common ways to determine which process is listening on a particular port in Linux:


1. Using lsof (List Open Files)

  • Command: bash sudo lsof -i :<port_number>
  • Example: bash sudo lsof -i :8080
  • Output:
    • The command shows the process name, PID, and other details of the process using the specified port.

2. Using netstat (Network Statistics)

  • Command: bash sudo netstat -tuln | grep :<port_number>
  • Example: bash sudo netstat -tuln | grep :8080
  • Output:
    • Displays the protocol (TCP/UDP), local address, foreign address, and the process (if run with -p option on supported versions).

Note: If netstat is not installed, you can install it via: bash sudo apt install net-tools


3. Using ss (Socket Statistics)

  • Command: bash sudo ss -tuln | grep :<port_number>
  • Example: bash sudo ss -tuln | grep :8080
  • Output:
    • Displays similar information to netstat but is faster and more modern.

Bonus: Using /proc Filesystem

  • Command: bash sudo grep <port_number> /proc/net/tcp
  • Example: bash sudo grep :1F90 /proc/net/tcp > Replace :1F90 with the hexadecimal representation of the port (e.g., 8080 in hex is 1F90).
  • This is a more manual approach and requires converting the port to hexadecimal.