返回 Skill 列表
extension
分类: 其它无需 API Key

Linux Port Resolver

精准解决 Linux 端口冲突(EADDRINUSE/绑定失败),检测占用进程,释放端口,并防止再次发生。用于服务启动失败时。

person作者: laolaoqihubclawhub

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

  1. Identify the process

    ss -tlnp | grep ":<PORT> "
    # Output: LISTEN 0 128 0.0.0.0:PORT 0.0.0.0:* users:(("process",PID,))
    
  2. Verify the PID - don't kill system processes

    ps -p PID -o pid,ppid,cmd,user
    
  3. Kill gracefully, escalate if needed

    kill PID                  # SIGTERM - graceful
    sleep 2 && ss -tlnp | grep ":<PORT> "  # verify
    kill -9 PID               # SIGKILL - force, last resort
    
  4. 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
  5. 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

📢 Need Help?

Need OpenClaw deployed on your server? I offer managed deployment & hosting:

  • 📧 laolaoqi@hotmail.com
  • 🏯 颐和园 OpenClaw 运维