Back to Blog

Address Already in Use: Find Which Process Uses a Port

Getting "address already in use"? Find the process holding the port with ss, lsof and fuser, stop it properly or change the port, and fix related errors.

Nodesty Team7 min readServers
The words Port in Use with ss, lsof and fuser on a dark Nodesty background

The "address already in use" error means that the port your application wants is already taken by another process. It shows up in many forms: Node.js says EADDRINUSE, nginx refuses to start, a Minecraft server prints FAILED TO BIND TO PORT and Docker reports port is already allocated. In every case, the fix starts with the same question: which process is holding the port?

In this guide we show how to find that process with ss, lsof and fuser, how to read the output, the usual culprits and how to stop them properly. At the end we cover the opposite problem: nothing listening at all.

What the error looks like

Only one process can listen on a given port, IP address and protocol at a time. When a second one tries, it gets an error like these:

# Node.js
Error: listen EADDRINUSE: address already in use :::3000

# nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

# Minecraft (Java Edition)
**** FAILED TO BIND TO PORT!
The exception was: java.net.BindException: Address already in use

# Docker
Bind for 0.0.0.0:80 failed: port is already allocated

The number in the message (3000, 80, 25565) is the port you need to investigate. If you're not sure what a port is, start with our What is a port? guide.

Find the process: ss, lsof and fuser

After connecting to your server over SSH, the quickest tool is ss, which is installed on every modern distribution:

sudo ss -tulpn | grep :80

-t and -u show TCP and UDP, -l only listening sockets, -p the process and -n numeric ports. Run it with sudo; otherwise the process column stays empty for services owned by other users. A typical line looks like this:

tcp   LISTEN 0      511      0.0.0.0:80      0.0.0.0:*    users:(("nginx",pid=1234,fd=6))

The process here is nginx with PID 1234. Two other tools give the same answer:

sudo lsof -nP -iTCP:80 -sTCP:LISTEN
sudo fuser -v 80/tcp

lsof lists the command, PID and user; fuser prints the PIDs that use the port. If either is missing, install it with sudo apt install lsof psmisc (on AlmaLinux, sudo dnf install lsof psmisc). For a UDP port, such as a Bedrock server on 19132, use sudo fuser -v 19132/udp.

To learn more about a PID, see its full command line and which systemd service it belongs to:

ps -fp 1234
systemctl status 1234

Reading the ss output

The Local Address:Port column tells you where the process listens:

AddressMeaning
0.0.0.0:80All IPv4 addresses, reachable from outside
[::]:80 / *:80All IPv6 addresses (often IPv4 too, depending on the app)
127.0.0.1:3306Only from the server itself (localhost)
203.0.113.10:80Only on that specific IP address of the server

LISTEN means the process is waiting for connections. If the process column shows systemd instead of an application, the port is held by a systemd socket unit; systemctl list-sockets shows which one. If it shows docker-proxy, a Docker container publishes the port.

The usual culprits

  • Apache and nginx together: Both want ports 80 and 443. Installing nginx on a server where Apache is already running (apache2 on Ubuntu, httpd on AlmaLinux) is the most common cause of the nginx bind error.
  • A second copy of the game server: A Minecraft or other game server started earlier in tmux or screen keeps running after you disconnect. Check with tmux ls and screen -ls.
  • A process that didn't exit: After a crash or a forced restart, an old Java or Node.js process can hang on with the port still open.
  • A Docker container: A container that publishes the same port with -p 80:80, possibly with a restart: always policy.
  • A systemd service: A service with Restart=always comes back a few seconds after you kill it.

Stopping it properly

If the port belongs to a systemd service, stop it through systemd. Use disable as well if it shouldn't start again at boot:

sudo systemctl stop apache2
sudo systemctl disable apache2

For a Docker container, find it by the published port and stop it:

docker ps --filter "publish=80"
docker stop container-name

A container with a restart policy starts again when Docker restarts; remove it with docker rm or change its port mapping if you don't need it. For a game server in tmux or screen, attach to the session and stop it with the server's own stop command so the world is saved.

Only when there's no manager behind the process, end it yourself:

kill 1234
# only if it is still running after a few seconds:
kill -9 1234

A plain kill sends SIGTERM and lets the application close cleanly. kill -9 ends it immediately and can lose unsaved data, so keep it as a last resort. sudo fuser -k 80/tcp kills every process on the port in one go, but it gives you no chance to check what you are killing first.

Changing the port instead

Sometimes both applications need to run. In that case, give one of them a different port: listen 8080; in an nginx server block, Listen 8080 in Apache's ports.conf, server-port in Minecraft's server.properties, the PORT variable or listen() call in Node.js, and -p 8080:80 in Docker. Ports below 1024 need root privileges, so pick a higher port for applications that run as a normal user. Don't forget to open the new port in the firewall; see How to use UFW.

To run several websites on ports 80 and 443 at the same time, put nginx in front as a reverse proxy instead; we cover it in How to install nginx.

TIME_WAIT and SO_REUSEADDR

After a server closes connections, ss -tan may show them in the TIME_WAIT state for about a minute. This normally doesn't block a restart: most servers, including nginx and Node.js, set the SO_REUSEADDR socket option and can listen again immediately. If your own application reports the error only right after a restart and works a minute later, set SO_REUSEADDR on its listening socket.

List all listening ports as a security check

The same command, without a filter, shows everything your server exposes:

sudo ss -tulpn

Go through the list and ask, for every line on 0.0.0.0 or [::], whether it really needs to be reachable from the internet. Databases such as MySQL (3306), PostgreSQL (5432) and Redis (6379) should usually listen on 127.0.0.1 only. Remove services you don't use and block the rest with the firewall. Our Linux commands guide covers other useful tools for this kind of check.

The opposite problem: connection refused

If clients get Connection refused or a timeout, check whether anything is listening at all:

sudo ss -tulpn | grep :3000
curl -I http://127.0.0.1:3000
  • No output: Nothing is listening. The application has stopped or crashed; check its logs (journalctl -u service-name). To have systemd restart it automatically, see How to create a systemd service.
  • Listening on 127.0.0.1: The application works locally but is not reachable from outside. Change its bind address to 0.0.0.0, or put nginx in front.
  • Listening on 0.0.0.0 but unreachable from outside: The firewall is blocking it. A quick Connection refused usually means nothing is listening or the firewall rejects the packet; a timeout usually means a firewall drops it. Open the port with sudo ufw allow 3000/tcp, or on AlmaLinux with firewall-cmd.

Docker users should remember that published ports can bypass UFW; details are in our How to install Docker guide.

Ports on Nodesty servers

Nodesty AMD Ryzen 9 9950X VPS and AMD EPYC 7763 VPS plans come with NVMe disks and full root access, so you can see every listening port and decide yourself which services run on which port. Daily backups are free on VPS plans and are kept for 7 days.

Frequently Asked Questions

What does "address already in use" mean?

It means the application tried to listen on a port that another process is already listening on. On the same IP address and protocol, only one process can listen on a given port at a time, so the second one fails to start. The fix is to find and stop the process that holds the port, or to give the new application a different port.

How do I find which process is using a port on Linux?

Run sudo ss -tulpn and filter by the port number, for example sudo ss -tulpn | grep :80. The last column shows the process name and its PID. sudo lsof -i :80 and sudo fuser -v 80/tcp give the same information in a different format.

I killed the process but the port is taken again. Why?

The process is most likely managed by systemd, Docker or a process manager that restarts it automatically. Stop it through its manager instead, for example with sudo systemctl stop service-name or docker stop container-name, and disable it if it should not start at boot.

Should I use kill -9 to free a port?

Only as a last resort. A plain kill sends SIGTERM, which lets the application save data and close cleanly. kill -9 ends the process immediately, so a game server or database can lose unsaved data. Try systemctl stop or a plain kill first and wait a few seconds.

Can Apache and nginx run on the same server?

Yes, but not both on ports 80 and 443. Either remove the one you don't need, or move one of them to another port, such as running Apache on 8080 behind nginx as a reverse proxy.

The port isn't in use but I still can't connect. What's wrong?

Check whether anything is actually listening with ss -tulpn. If the application listens only on 127.0.0.1, it is reachable only from the server itself. If it listens on 0.0.0.0 but you still can't connect from outside, the firewall is probably blocking the port.

Nodesty

About the author

Nodesty Team · Infrastructure & Support

The Nodesty team runs our servers, network and DDoS protection day to day and answers customer support requests around the clock. These guides come from that work.

Related articles

Launch your server now.

Build, scale, and conquer without limits on Nodesty's premium infrastructure.

                                                                                                                                                                                                                            
                                                                                                                                                                                                                            
                                                                                                                                                                                                                            
                                                                                                                             ············································                                                   
                                                ··································································································..........···························                                     
                                       ················..........................................................................................................................··············                             
                                  ·············.................::::::::::::::::::::::::::::::::::::::::::::::....................:::::::::::::::::::::::::::::::::::::::................···········                        
                             ············................:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::............·········                     
                         ············.................:::::::::::::::::::::::::::::::::::::::::::::::::::------------::::::::::::::::::::::::::::::----------------:::::::::::::::::::::..........········                  
                    ············......................::::::::::::::::::::::::::::::::::::------------------------------------------------------------------------------------:::::::::::::.........········                
                ··········.............................................::::::::::::::::::-------------==========================================-----------------------------------:::::::::::........·······               
             ········..................:.....................................::::::::::--------=======+++++++++++++++++++++++++++++++++++++=========================------------------::::::::::.......·······              
           ······.........::::::::::::::::::::................................:::::::-----=====++++xxxxxx**************************xxxxxxxxx++++++++++++++===================------------::::::::.......·······             
          ·····.......:::::::::::::::::::::::::::.............................:::::----===+++xxx****%%%%&&&&&&#############&&&&&&&%%%%%*******xxxxxxxx++++++++++++++==============----------:::::::......······             
         ····......::::::::-------------:::::::::::..........................::::---===+++xx***%%%&&&####@@@@@@@@@@@@@@@@@@@@@@@@####&&&&&%%%%*******xxxxxxxxx+++++++++++++===========--------::::::......·····             
        ····.....:::::::--------------------:::::::::.......................::::---===++xxx**%%&&&###@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@###&&&&%%%%%********xxxxxxxxxxx++++++++++++========------::::::.....······            
        ····.....:::::--------------------------::::::::....................::::---===++xx***%%&&&####@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@###&&&&&%%%%%**********xxxxxxxxxxxxx+++++++++=======------:::::.....·····            
        ····....::::::-------=============---------:::::::::................:::::---===+++xx***%%%&&&#####@@@@@@@@@@@@@@@@@@@@@@@@@#####&&&&&%%%%%%*************xxxxxxxxxxxxxx+++++++++======-----:::::....·····            
         ····....:::::-------================---------:::::::::...............:::::----===++++xxx***%%%%&&&&&&#################&&&&&&%%%%%%%*******************xxxxxxxxxxxxxxxxx++++++++======----:::::....·····            
         ·····....:::::--------=================---------::::::::::..............:::::::-----====+++++xxxxxx**************************xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx++++++++=====-----::::....·····            
          ·····.....:::::--------=================----------:::::::::::.................:::::::::-------=============++++++++++++++++++++++++++++++++++++xxxxxxxxxxxxxxxxxxxxxxx++++++++======-----::::....·····            
            ·····.....:::::::----------===========-------------::::::::::::.........................::::::::::::::::::------------------=============+++++++++++++++++++++++++++++++++=======-----::::.....·····            
              ······......:::::::---------------------------------:::::::::::::........................................:::::::::::::::-----------============+++++++++++++++++++++========------:::::.....·····             
                 ······........:::::::::---------------------------:::::::::::::::::...........................................:::::::::::::------------=============================--------::::::.....······              
                    ·········.........:::::::::::::::-------------::::::::::::::::::::::::.......................................::::::::::::::::--------------------------------------::::::::......·······                
                          ··········............::::::::::::::::::::::::::::::::::::::::::::::::::................................::::::::::::::::::::::::::-------------:::::::::::::::.........········                   
                                  ············..................:::::::::::::::::::::::::::::::::::::::::::.........................:::::::::::::::::::::::::::::::::::::................···········                        
                                             ················.............................................................................................................·················                                 
                                                           ······················................................................................···························                                                
                                                                               ·········································································