netstat command on MacOS
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
- Open the Terminal app on your MacOS device.
- Type in the following command:
sudo lsof -iTCP -sTCP:LISTEN -n -P
- Press Enter. You will be prompted to enter your administrator password.
- 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 ofiTCP
. - 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