How to check if a port is in use using terminal [Linux or macOS]


If you want to know if a port is in use or not, you can do that using netstat command on the terminal on your Linux or macOS system,

$ netstat -an

Active Connections

  Proto  Local Address          Foreign Address        State
  TCP    0.0.0.0:135            0.0.0.0:0              LISTENING
  TCP    127.0.0.1:27015        0.0.0.0:0              LISTENING
  TCP    127.0.0.1:27015        127.0.0.1:60040        ESTABLISHED
  TCP    192.168.0.109:139      0.0.0.0:0              LISTENING
  TCP    [::]:135               [::]:0                 LISTENING
  TCP    [::]:445               [::]:0                 LISTENING
  TCP    [::]:49665             [::]:0                 LISTENING
  TCP    [::1]:49709            [::]:0                 LISTENING
  UDP    0.0.0.0:5050           *:*
  UDP    0.0.0.0:5353           *:*
  UDP    127.0.0.1:52554        *:*
  UDP    127.0.0.1:52555        *:*
  UDP    [::]:5353              *:*
  UDP    [::1]:1900             *:*
  UDP    [::1]:51995            *:*

You will see such a huge list of active commections and port, you can merge grep command to look for the port,

Example: $ netstat -an | grep <port-name>
$ netstat -an | grep 5353
  UDP    0.0.0.0:5353           *:*
  UDP    0.0.0.0:5353           *:*
  UDP    192.168.0.108:5353     *:*
  UDP    [::]:5353              *:*
  UDP    [::1]:5353             *:*
Check if a port is in use using terminal netstat command
Check if a port is in use using terminal netstat command
Advertisements
Try Out Code2care Dev Tools:

Advertisements



Android Java Linux Microsoft Google Python macOS Notepad++ Microsoft Teams CSS PHP SharePoint Html Linux C Programs Bootstrap jQuery Sublime Android Studio Facebook Eclipse WhatsApp News MySQL Json HowTos JavaScript FTP S3


Advertisements


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Tutorials, Trouble-Shooting steps, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.
🎉 We are celebrating the 10th years of Code2care! Thank you for all your support! We hope we made a difference.
We strong support Gender Equality & Diversity.

We stand in solidarity with Ukraine - Make a donation to UNHCR - https://donate.unhcr.org/in/en-in/ukraine-emergency