Find who owns a port

Show which process uses a port; -nP skips DNS and service name lookups, so it is faster

lsof -nP -i :<port>

tool
lsof19 commands
tags
lsofnetworktroubleshootingdebug

More lsof commands

  • lsof -nP -iTCP -sTCP:LISTEN

    List every listening TCP socket with its PID, without name lookups; the newer way is ss -ltnp

  • lsof +L1

    Find deleted files that are still open and use disk space, the reason why df says the disk is full and du does not

  • lsof /mnt/<name>

    Show the processes that cause the "device busy" error on umount; pass the mount point path

  • lsof -t -i:<port> | xargs -r kill

    Kill the process that holds a port; -t prints only PIDs, -r skips kill if nothing is found

  • lsof -nP -i -sTCP:CLOSE_WAIT

    Find sockets that the app forgot to close; a growing CLOSE_WAIT count means an fd or connection leak

all 19 lsof commands