Skip to content

netstat ss on MacOS

homepage-banner

Introduction

When troubleshooting network issues on your MacOS device, it is important to know which TCP/UDP ports are being used by which services. This information can help you diagnose and resolve connection issues, as well as ensure that your network is secure. In this blog post, we will guide you on how to find out TCP/UDP port and service on your MacOS device.

Using lsof

  1. Open the Terminal app on your MacOS device.
  2. Type in the following command: sudo lsof -iTCP -sTCP:LISTEN -n -P
  3. Press Enter. You will be prompted to enter your administrator password.
  4. This will display a list of all TCP ports that are currently open and the services that are using them. You can also specify UDP ports by typing iUDP instead of iTCP.
  5. If you want to see all established connections, type in the following command: sudo lsof -iTCP -n -P | grep ESTABLISHED
echo "### TCP LISTEN ###"
lsof -nP -iTCP -sTCP:LISTEN
echo "### UDP LISTEN ###"
lsof -nP -iUDP -sTCP:LISTEN

Using procs

brew install procs
procs

For friendly output, add below to ~/.procs.toml after installing the tool.

[[columns]]
kind = "TcpPort"
style = "BrightYellow|Yellow"
numeric_search = true
nonnumeric_search = false
align = "Left"

[[columns]]
kind = "UdpPort"
style = "BrightGreen|Green"
numeric_search = false
nonnumeric_search = true
align = "Left"

Source: https://github.com/dalance/procs

Feedback