Skip to content

netstat command 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 Terminal to find TCP/UDP port and service

  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

Summary

echo "### TCP LISTEN ###"
lsof -nP -iTCP -sTCP:LISTEN
echo "### UDP LISTEN ###"
lsof -nP -iUDP -sTCP:LISTEN
Leave your message