Find out TCP/UDP port and service 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
Small world. Big idea!
- Welcome to visit the knowledge base of SRE and DevOps!
- License under CC BY-NC 4.0
- No personal information is collected
- Made with Material for MkDocs and generative AI tools
- Copyright issue feedback me#imzye.com, replace # with @
- Get latest SRE news and discuss on Discord Channel