5 ways to Check a remote port is open in Linux

Updated: Jun 8

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 install the package if we choose nc, nmap,telnet.




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)); "




330 views
udemylinux.png

Join our newsletter! Get a free cloud server!  Never miss a post!

Thanks for submitting!