A new web server is supposed to start on port 80 and dies immediately. The journal says Address already in use. A port is taken per address – some socket already holds exactly this combination. ss tells you who, in one line.
Symptom
sudo journalctl -u web-neu -o cat --no-pager | tail -3 OSError: [Errno 98] Address already in use web-neu.service: Main process exited, code=exited, status=1/FAILURE web-neu.service: Failed with result 'exit-code'.
A colleague starts a second version of the web server on web at 10.2.0.10:80 without stopping the old one. systemctl is-active reports failed.
Diagnosis
ss with a port filter and process shows the holder, ps the matching systemd unit.
sudo ip netns exec web ss -ltnp 'sport = :80'
State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess
LISTEN 0 5 10.2.0.10:80 0.0.0.0:* users:(("python3",pid=45984,fd=3))
ps -o unit= -p 45984
web-http.service
Causes
same addressThe old service is still running
Another socket holds the same address with the same port. In practice often a forgotten test server, an old container or a second service with the same default configuration.
0.0.0.00.0.0.0 covers all addresses
Starting on 0.0.0.0:80 collides too, because 0.0.0.0 includes the already taken 10.2.0.10. Another address of the same host, however, is free.
sudo ip netns exec web ss -ltn 'sport = :80' State Recv-Q Send-Q Local Address:Port Peer Address:PortProcess LISTEN 0 5 10.2.0.10:80 0.0.0.0:* LISTEN 0 5 10.10.0.10:80 0.0.0.0:*
Fix
sudo systemctl reset-failed web-neu sudo systemd-run --unit=web-neu --property=WorkingDirectory=/home/ubuntu/www \ ip netns exec web python3 -m http.server 80 --bind 10.10.0.10
Don't: Kill the holder with kill -9 on a hunch. First find out with ss and ps which service it is and who owns it.
Network debugging, Day 5: who is listening? Reading ss, bind addresses, Address already in use and connection states.
Go to day 5 →
FAQ
Why does starting on 0.0.0.0 fail as well?
0.0.0.0 means “all addresses” and therefore includes the one already taken. Only an address on which nobody holds the port yet is free.
How do I find the systemd unit for a PID?
ps -o unit= -p PID prints the unit without a header. That tells you which service and which owner is behind it.