Skip to main content

Show used ports in Linux

  • Blog
  • 0 Kommentare

Websites communicate on specific ports. For instance, behind a web address with HTTP, there's always a request on port 80. Once HTTPS is used, the browser requests a webpage from the webserver on port 443. For this, a webserver is required. Widely used are NGINX and Apache.

Personally, I prefer NGINX because it can be used as both a webserver and a reverse proxy. Reverse proxy means that internally, the request can be forwarded to another website or to an internally running Apache or Docker container. Also, configuring an encrypted connection with NGINX is very straightforward, and it handles many requests without issue.

To check for occupied ports under Linux, there are several methods available. Here are three of the most common:

1. Checking Open Ports with lsof:

lsof can be installed on Debian/Ubuntu with the command:

   sudo apt install lsof

One way to display occupied ports under Linux is to use lsof (List Open Files). This tool can display not only open files but also network connections. Here's how you can use it:

   sudo lsof -i -P -n | grep LISTEN

This command displays a list of all open network connections that are listening (LISTEN) on your system. Here's a brief explanation of the options:

  • -i: Displays Internet network connections.
  • -P: Prevents the conversion of port numbers to service names.
  • -n: Displays numerical addresses (no name resolution).
  • grep LISTEN: Filters the output to display only connections waiting for connections (LISTEN).

2. Netstat Command:

The netstat command is a versatile tool for displaying various network information, including the list of currently occupied ports. Open the terminal and enter the following command:

   netstat -tuln

This command displays a list of TCP (-t) and UDP (-u) ports along with their status (-l for listening ports, -n for numeric output instead of name resolution).

3. SS Command:

The ss command is a more modern alternative to netstat and offers similar functionality but is more efficient. Enter the following command in the terminal:

   ss -tuln

This command also displays a list of TCP (-t) and UDP (-u) ports along with their status (-l for listening ports, -n for numeric output instead of name resolution).

These methods provide additional ways to view occupied ports on your Linux system and give you insight into active network connections.

By submitting your data, you agree that all entered data may be saved and displayed as a comment.

🤖 Cookies

We use cookies to improve your experience. Find out more in our privacy page.