How to find what is using a port on Mac
Short answerOn macOS, run lsof -nP -iTCP:<port> -sTCP:LISTEN to see which process is listening on a port. To list every listening port, run lsof -nP -iTCP -sTCP:LISTEN. Portmole shows the same list in the menu bar, with each dev server's page title and project folder.
One port
lsof -nP -iTCP:8080 -sTCP:LISTEN-n and -P stop lsof from resolving hostnames and port names, which makes it faster and keeps the numbers readable. -iTCP:8080 limits it to TCP port 8080 and -sTCP:LISTEN keeps only listening sockets, not connections that happen to use that port.
Every listening port
lsof -nP -iTCP -sTCP:LISTENColumns to look at: COMMAND is the program, PID is what you pass to kill, USER is the owner, and NAME shows the address and port, for example *:3000 (all interfaces) or 127.0.0.1:3000 (this Mac only).
Why `*:3000` matters
A server bound to 127.0.0.1 can only be reached from your own Mac. One bound to * or 0.0.0.0 is reachable from anyone on your network. That is useful for testing on a phone, and worth knowing before you do it on public Wi-Fi.
Using netstat instead
netstat -anv -p tcp | grep LISTENmacOS netstat shows listening sockets too, and the -v flag adds the PID. lsof is easier to filter, which is why most guides use it.
Seeing other users' processes
Without sudo, lsof only shows your own processes. Add sudo to see everything, such as system services. Portmole lists them too, under Apps and Other, but only lets you close your own.
Without the terminal
Portmole is a free macOS menu bar app that lists every process listening on a port and closes it with one click, so you don't need to remember any of these commands.
Frequently asked questions
What command shows all open ports on a Mac?
lsof -nP -iTCP -sTCP:LISTEN lists every TCP port something is listening on, with the process name and PID.
Why does lsof show nothing for my port?
Either nothing is listening on it, or the process belongs to another user. Try the command again with sudo.
What is the difference between 127.0.0.1 and * in lsof output?
127.0.0.1 means the server only accepts connections from this Mac. * means it accepts connections on every network interface.
Skip the terminal
Portmole shows every port your Mac is listening on and closes any of them with one click. Free, signed and notarized, about 7 MB.
Download Portmole for Mac