DEV Community

Mohammed Samgan Khan
Mohammed Samgan Khan

Posted on • Originally published at codebysamgan.com

1

How to check all ports in use in linux/Mac

When you work with NodeJS and micro-service architecture by the end of the day there are a number of ports which you start using.

To check which port is already in use, use the following command.

For Linux

netstat -lnp | grep node
Enter fullscreen mode Exit fullscreen mode
  • -l: Show only listening ports.
  • -n: Show numerical addresses instead of resolving hostnames.
  • -p: show type of port (grep works on this)
ss -tuln
Enter fullscreen mode Exit fullscreen mode
  • -t: Show TCP ports.
  • -u: Show UDP ports.
  • -l: Show only listening ports.
  • -n: Show numerical addresses instead of resolving hostnames.
lsof -i -n -P | grep node
Enter fullscreen mode Exit fullscreen mode
  • i: Specifies that you're interested in network-related information, specifically open network connections and listening sockets.
  • -n: Prevents lsof from attempting to resolve IP addresses to hostnames. Shows numerical IP addresses instead.
  • -P: Prevents lsof from resolving port numbers to service names. Shows numerical port numbers instead.

For Mac

lsof -i -n -P | grep node
Enter fullscreen mode Exit fullscreen mode
  • i: Specifies that you're interested in network-related information, specifically open network connections and listening sockets.
  • -n: Prevents lsof from attempting to resolve IP addresses to hostnames. Shows numerical IP addresses instead.
  • -P: Prevents lsof from resolving port numbers to service names. Shows numerical port numbers instead.

Additionally, you can use graphical tools like lsof and network monitoring tools like nmap for more advanced analysis of open ports and network connections.

Heroku

Build apps, not infrastructure.

Dealing with servers, hardware, and infrastructure can take up your valuable time. Discover the benefits of Heroku, the PaaS of choice for developers since 2007.

Visit Site

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs