How to Free a Busy TCP/IP Port in Linux

A practical walkthrough of fuser, lsof, and ss for tracking down and killing whatever is blocking a port

Knowing how to free a port in Linux comes down to one thing: finding whatever process is still holding it and telling it to let go. A "port already in use" error usually means an old process never released it, and until you find and stop that process, your app, container, or service simply will not start.

Syntax






LinuxTeck
fuser -k PORT/tcp
kill -9 $(lsof -t -i :PORT)
ss -tulpn | grep :PORT

I once spent a good twenty minutes trying to restart a Node app on port 3000 before realizing a crashed test run from the night before was still sitting there holding it hostage, and it took one fuser -k to fix what felt like a much bigger problem. Once you know these three commands you will never see EADDRINUSE or "address already in use" as a mystery again.

Quick Answer:

This finds whatever is bound to TCP port 8080 and kills it in a single command, no PID lookup needed.






LinuxTeck
linuxteck@ubuntu:~$ sudo fuser -k 8080/tcp


How to Install fuser and lsof to Free a Port in Linux

Both tools ship in the standard repos on pretty much every distro, they are just sometimes not installed by default on minimal server images. ss usually comes preinstalled as part of iproute2.

Ubuntu / Debian:






LinuxTeck
linuxteck@ubuntu:~$ sudo apt install psmisc lsof
Sample Output (Ubuntu/Debian)
Setting up psmisc (23.7-1) ...
Setting up lsof (4.95.0-1) ...
Processing triggers for man-db (2.11.2-2) ...

RHEL / Rocky Linux / Fedora:






LinuxTeck
linuxteck@rocky:~$ sudo dnf install psmisc lsof
Sample Output (RHEL/Rocky/Fedora)
Installed:
lsof-4.95.0-6.el9.x86_64 psmisc-23.4-3.el9.x86_64
Complete!

Arch Linux:






LinuxTeck
linuxteck@arch:~$ sudo pacman -S psmisc lsof
Sample Output (Arch Linux)
resolving dependencies...
installing psmisc...
installing lsof...

1. Check Which Process Is Using a Port with ss

ss is faster than the old netstat and ships with almost every modern distro, so it is a good first stop when you want to free a port in Linux. Run it with sudo, otherwise the process owner and PID for services you do not own get hidden from the output. Add the port number to grep straight to the line you care about.






LinuxTeck
linuxteck@ubuntu:~$ sudo ss -tulpn | grep :3000
Sample Output
tcp LISTEN 0 511 0.0.0.0:3000 0.0.0.0:* users:(("node",pid=8421,fd=22))

The pid= value in that last column is the number you will hand to kill in a moment. Here it is 8421. If you would rather watch running processes live instead of a one time snapshot, our htop command guide is a good next read.

2. Get the Same Info with lsof

Some people find lsof easier to read since it prints the command name up front. The -i flag filters to network connections, and you can target a single port with a colon.






LinuxTeck
linuxteck@ubuntu:~$ sudo lsof -i :3000
Sample Output
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 8421 linuxteck 22u IPv4 481922 0t0 TCP *:3000 (LISTEN)

Run this with sudo, plain lsof quietly skips processes it does not have permission to see and you will think the port is free when it is not.

3. Kill a Process by Its PID

Once you have the PID from ss or lsof, the plain kill command sends a polite SIGTERM asking the process to shut itself down cleanly.






LinuxTeck
linuxteck@ubuntu:~$ kill 8421
Sample Output
[1]+ Terminated node server.js

Keeping an eye on overall system load while you troubleshoot helps too, see our system monitoring cheat sheet for a full rundown.

4. Free a Port in Linux Instantly with fuser

fuser skips the lookup step entirely. Point it straight at the port and protocol and it finds and kills the owning process by itself.






LinuxTeck
linuxteck@ubuntu:~$ sudo fuser -k 8080/tcp
Sample Output
8080/tcp: 8421

The number printed back is the PID that got killed, worth glancing at before you move on in case it was not the process you expected. This is the fastest single command to free a port in Linux when you do not need to inspect anything first.

5. Force Kill a Stubborn Process with kill -9

Sometimes SIGTERM gets ignored, usually because the process is stuck or misbehaving. SIGKILL through -9 does not ask, it just ends the process immediately at the kernel level. Piping to xargs -r instead of using command substitution directly is the safer habit, if the port turns out to be empty, kill gets called with zero arguments and just throws a usage error instead of doing something unexpected.






LinuxTeck
linuxteck@ubuntu:~$ lsof -t -i :3000 | xargs -r kill -9
Sample Output
[1]+ Killed node server.js

Production Tip:

Reach for plain kill first and only fall back to -9 when the process ignores it for a few seconds. SIGKILL skips cleanup handlers, so a database process killed this way can leave behind a messy shutdown.

6. Free Up a UDP Port

Everything so far defaulted to TCP. DNS resolvers, some VPN daemons, and streaming tools often bind UDP instead, so tell fuser the protocol explicitly if you need to free a UDP port in Linux.






LinuxTeck
linuxteck@ubuntu:~$ sudo fuser -k 53/udp
Sample Output
53/udp: 1122

7. Kill Processes Across Multiple Ports at Once

fuser accepts more than one port in the same call, which saves time when you need to free several ports in Linux at once after a crash leaves multiple services stuck.






LinuxTeck
linuxteck@ubuntu:~$ sudo fuser -k 3000/tcp 3001/tcp 8080/tcp
Sample Output
3000/tcp: 8421
3001/tcp: 8433
8080/tcp: 8455

8. Confirm the Port Is Actually Free Now

Do not assume it worked just because the terminal did not error out. Run the same check you started with and make sure nothing prints back.






LinuxTeck
linuxteck@ubuntu:~$ sudo lsof -i :3000
Sample Output

No rows at all means the port is clear. If you would rather have a dedicated networking command for this kind of check, our ss command guide covers a few more flags worth knowing.

9. Common Mistake: Killing the Wrong PID When Several Processes Share a Port

A lot of people grab the first PID they see in lsof output and kill it without checking, which is fine for a single process but risky the moment a port has more than one entry, like a master process and its worker forks. Rushing this step is one of the more common ways people fail to actually free a port in Linux and end up back where they started.






LinuxTeck
linuxteck@ubuntu:~$ sudo lsof -i :5432
Sample Output
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
postgres 1204 postgres 5u IPv4 331092 0t0 TCP *:5432 (LISTEN)
postgres 1301 postgres 7u IPv4 331411 0t0 TCP *:5432 (LISTEN)

Common Mistake:

Killing PID 1301 here just kills a worker, the port stays busy because the parent process at 1204 is still holding it. For a service like PostgreSQL, stop it properly through systemctl instead of hunting individual PIDs. There is also a bigger trap if the service has Restart=always set in its systemd unit file. Kill the PID manually and systemd treats it as a crash, then spawns a brand new process on the exact same port within a second or two, making it look like your kill command did nothing. Always stop the service through systemctl when it is managed by systemd, never through kill or fuser directly.






LinuxTeck
linuxteck@ubuntu:~$ sudo systemctl stop postgresql
Sample Output

Checking active processes before you touch anything is a habit worth building, our ps command guide and this process management cheat sheet are both handy to keep nearby.

10. Free a Port Held by a Docker Container

Killing the host process will not help here, the port is mapped through Docker's networking layer, so freeing a Docker-bound port in Linux means stopping the container itself.






LinuxTeck
linuxteck@ubuntu:~$ docker ps --filter "publish=8080"
Sample Output
CONTAINER ID IMAGE PORTS NAMES
a13f9c2b0d21 nginx:latest 0.0.0.0:8080->80/tcp web_test





LinuxTeck
linuxteck@ubuntu:~$ docker stop a13f9c2b0d21
Sample Output
a13f9c2b0d21

Production Tip:

If you are testing container port conflicts on a throwaway VPS before rolling changes out to production, it is worth comparing providers first. Our DigitalOcean vs Vultr comparison breaks down pricing and performance if you are shopping around for a test box.


Conclusion

Between ss, lsof, and fuser you now have every method you need to free a port in Linux, from spotting the process to force killing it without ever memorizing a PID by hand. If you deal with services conflicting on boot, pairing this with our firewall-cmd guide and networking commands roundup will round out your troubleshooting toolkit. Which of these commands do you reach for first when a port gets stuck? Share your experience in the comments below.

LinuxTeck - A Complete Linux Learning Blog
From your first terminal command to advanced sysadmin skills, every guide here is written in plain English with real examples you can run right now.

Support My Work

Thank you for reading and for being part of this journey. If this article saved you time, consider buying me a coffee. Every contribution helps me keep producing in-depth, practical Linux content for readers like you.

Thank you for your endless support

About Aneeshya S

Aneeshya S is a Senior Linux Trainer and System Administrator with over 10 years of experience. She actively follows emerging technologies and industry trends. Outside the terminal, she enjoys music and travel.

View all posts by Aneeshya S →

Leave a Reply

Your email address will not be published.

L