0
0
Linux-cliHow-ToBeginner · 3 min read

How to Check Open Ports on Linux: Simple Commands

To check open ports on Linux, use the ss -tuln or netstat -tuln commands to list listening TCP and UDP ports. Alternatively, lsof -i shows open network connections with process details.
📐

Syntax

Here are common commands to check open ports on Linux:

  • ss -tuln: Shows listening TCP and UDP ports with numeric addresses.
  • netstat -tuln: Lists listening TCP and UDP ports (may require installation).
  • lsof -i: Lists open internet sockets with process info.
bash
ss -tuln
netstat -tuln
lsof -i
💻

Example

This example uses ss -tuln to show open ports and their states.

bash
ss -tuln
Output
Netid State Recv-Q Send-Q Local Address:Port Peer Address:Port udp UNCONN 0 0 0.0.0.0:68 0.0.0.0:* tcp LISTEN 0 128 0.0.0.0:22 0.0.0.0:* tcp LISTEN 0 128 [::]:22 [::]:*
⚠️

Common Pitfalls

Common mistakes when checking open ports include:

  • Running netstat without root privileges may show incomplete info.
  • Using ss without -n can show hostnames instead of numeric ports, which is slower.
  • Not installing net-tools package if netstat is missing.
bash
netstat -tuln
# Wrong: netstat -tul (missing -n shows names, slower)
# Right: netstat -tuln
📊

Quick Reference

CommandDescription
ss -tulnShow listening TCP/UDP ports with numeric addresses
netstat -tulnList listening TCP/UDP ports (may need net-tools)
lsof -iList open internet sockets with process info
sudo lsof -i :80Check which process uses port 80
ss -tunapShow all TCP/UDP ports with process info (requires root)

Key Takeaways

Use ss -tuln for a fast, modern way to list open ports.
Install net-tools if netstat is not available.
Add -n to avoid slow hostname resolution.
Use lsof -i to see which processes use network ports.
Run commands with sudo for complete information.