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


















Copyright © Code2care 2024 | Privacy Policy | About Us | Contact Us | Sitemap