howtouselinux

6 ways to Check a remote port is open in Linux

Table of Contents

 

Checking remote port status is a common task for Linux admin. Now we collect 5 different ways for this task. We don’t need to install any package if we use the following two python commands. We need to install the package if we choose nc, nmap,telnet.

The following commands can be used to check if a port is open on the remote server in Linux.

  • Use nc command nc -zvw10 192.168.0.1 22
  • Use nmap command nmap 192.168.0.1 -p 22
  • Use telnet command telnet 192.168.0.1 22
  • Use python telnet module
  • Use python socket module
  • Use curl command

 

Use nc command to check the remote port is open

$ nc [-options] [HostName or IP] [PortNumber]

$ nc -zvw10 192.168.0.1 22

  • z: zero-I/O mode which is used for scanning
  • v: for verbose output
  • w10: timeout wait seconds

 

Use nmap to check the remote port is open

$ nmap [-options] [HostName or IP] [-p] [PortNumber]

nmap 192.168.0.1 -p 22

Use telnet to check the remote port is open

$ telnet [HostName or IP] [PortNumber]

telnet 192.168.0.1 22

Use python telnet to check remote port is open

python -c “import telnetlib; tel=telnetlib.Telnet(‘192.168.0.1′,’22’,10); print tel; tel.close()”

Use python socket to check remote port is open

Python -c “import socket; s = socket.socket(); s.settimeout(10); s.connect((‘192.168.0.1’, 22)); ”

Use curl to check remote port is open

We have another solution for this with the curl command. curl -v telnet://192.168.0.1:22

 

Understanding TCP Connection with Examples

4 Ways to Check Network Status on Linux

Linux Learning Guide:

Share on facebook
Facebook
Share on twitter
Twitter
Share on linkedin
LinkedIn
Liquid Web Managed Word Press