Linux Port Resolver
Quick fix port conflicts on Linux without guesswork.
Quick Commands
# Find what's on a port
ss -tlnp | grep :PORT
# Alternative if ss not available
netstat -tlnp 2>/dev/null | grep :PORT
# Also check IPv6
ss -tlnp | grep :PORT
Resolution Steps
-
Identify the process
ss -tlnp | grep ":<PORT> " # Output: LISTEN 0 128 0.0.0.0:PORT 0.0.0.0:* users:(("process",PID,)) -
Verify the PID - don't kill system processes
ps -p PID -o pid,ppid,cmd,user -
Kill gracefully, escalate if needed
kill PID # SIGTERM - graceful sleep 2 && ss -tlnp | grep ":<PORT> " # verify kill -9 PID # SIGKILL - force, last resort -
Or reconfigure - change the port in the service config instead
- systemd: edit
/etc/systemd/system/SERVICE.service, change port,systemctl daemon-reload && systemctl restart SERVICE - Docker: change
ports:mapping in docker-compose.yml - Custom app: check config file or env var for port setting
- systemd: edit
-
Prevent recurrence with ExecStartPre in systemd
[Service] ExecStartPre=/bin/sh -c 'kill -9 $(ss -tlnp | grep ":PORT " | grep -oP "pid=\\K\\d+") 2>/dev/null; true'
Safety Checklist
- Confirmed the port is actually in use
- Identified the PID correctly
- PID is not PID 1 or a critical system daemon
- Verified there's no other instance still running
- Checked both IPv4 and IPv6 listeners