How to check a port in use in linux

If you are running your application with a specific port in Linux server (ubuntu, centos, ..) but suddenly you got an error, for example:

Error: listen EADDRINUSE: address already in use :::8888

or you want to check a port that either has ready used or not to connect the app to it. By following, methods can help you checking.

1. Using the lsof command:

$ lsof -i:8888

or get all listen to ports:

$ lsof -i | grep LISTEN

2. Using the ss command:

$ ss -lntup | grep LISTEN

or get a specific port:

$ ss -lntup | grep 8888

3. Using the netstat command:

If your server does not have the netstat, you have to install it first:

  • Ubuntu:
$ sudo apt install netstat -y
  • Centos:
$ sudo yum install netstat -y

Let’s start checking:

$ netstat -tulpn | grep LISTEN

or get your port:

$ netstat -tulpn | grep 8888

This post is shown you three simple ways of checking a port in use in Linux, each of them will have advantages and disadvantages accordingly please choose the best utility which is suitable for you.
Thank you for reading!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s