The “Address already in use” error: how to find out what is listening on a port, and how to stop the service or end the process properly.
If a service fails to start with the error “Address already in use”, the port is already taken by another program. First find out which one.
What is using the port
sudo ss -ltnp 'sport = :80'The output shows the program name and its process number (pid). The option letters mean: l — listening ports, t — TCP (u — UDP), n — port numbers instead of names, p — processes. To see all ports in use at once, run sudo ss -ltnp.
You can get the same information with sudo lsof -i :80 or sudo fuser -v -n tcp 80, if they are installed. On FreeBSD, use sockstat -4 -l -p 80.
How to free the port
If a service is holding the port, stop it properly — that way it will not start again by itself:
sudo systemctl stop nginx
sudo systemctl disable nginx # if you do not need the service after a reboot eitherIf it is a standalone or hung process, end it by its process number:
sudo kill 1524 # ask the process to exit
sudo kill -9 1524 # force it — if the process is still alive after a few secondskill -9 does not give the program a chance to save its data. Never stop a database this way — stop it through its own service.Didn’t find the answer? Ask our support team — we’ll help.