Commands to check if a port is open on our PC / Server or another remote

Sometimes we need to know if X port is open on a remote computer (or server), at that moment we have not a few options or tools to use:

Nmap

The first solution that many of us think is: Nmap , see article called: See open ports with NMap and measures to protect ourselves 

In case you do not want to do a whole scan, but simply want to know if a certain port is open on X computer / server, it would be like this:

nmap {IP_O_DOMINIO} -p {PUERTO} | grep -i tcp

Example:

nmap localhost -p 22 | grep -i tcp

O well:

nmap 127.0.0.1 -p 22 | grep -i tcp

What this does is simple, it asks the IP or Host if the given port is open or not, then grep filters and only shows the line they want to read, the one that tells them if it is open (open) or closed (closed) that port:

Nmap

Well ... yes, nmap (Network exploration and port probing tool) works for us, but there are still other variants where you have to type less 🙂

nc

nc or netcat, it is a much simpler option to know if a port is open or not:

nc -zv {IP_O_DOMINIO} {PUERTO}

That is:

nc -zv 192.168.122.88 80

Here is a screenshot doing a test to a port that is open (80) and another to another port that is not (53):

nc

El -zv what it does is simple, the v allows us to see if the port is open or not, while z closes the connection as soon as the port is checked, if we do not put the z then we would have to do a Ctrl + C to close the nc.

telnet

This is the variant that I used for a while (due to ignorance of the aforementioned), in turn telnet serves us much more than just knowing if a port is open or not.

telnet {IP_O_HOST} {PUERTO}

Here's an example:

telnet 192.168.122.88 80

The problem with telnet is closing the connection. In other words, on certain occasions we will not be able to close the telnet request and we will be forced to close that terminal, or otherwise in another terminal do a telnet killall or something similar. That is why I avoid using telnet unless I really need to.

The end!

Anyway, I hope this has been interesting for you, if someone knows any other way to know if a port is open or not on another computer, leave it in the comments.

regards


The content of the article adheres to our principles of editorial ethics. To report an error click here!.

14 comments, leave yours

Leave a Comment

Your email address will not be published.

*

*

  1. Responsible for the data: Miguel Ángel Gatón
  2. Purpose of the data: Control SPAM, comment management.
  3. Legitimation: Your consent
  4. Communication of the data: The data will not be communicated to third parties except by legal obligation.
  5. Data storage: Database hosted by Occentus Networks (EU)
  6. Rights: At any time you can limit, recover and delete your information.

  1.   Tesla said

    These commands will come in handy for me when I connect via SSH!

    Thank you!

  2.   anon said

    Is there a graphical application to do the same?

    1.    KZKG ^ Gaara said

      Well you can always install zenmap which uses nmap from behind :)

    2.    vidagnu said

      If with nmapfe, it is the graphical interface that comes with nmap.

  3.   Konozidus said

    With netcat it tells me that z is an invalid option, without it it works perfectly, and in $ man nc, it doesn't appear either. Where did it come from?

    https://blog.desdelinux.net/wp-content/uploads/2013/12/Captura-de-pantalla-de-2013-12-29-011908.png

    1.    KZKG ^ Gaara said

      -z: Specifies that nc should just scan for listening daemons, without sending any data to them. It is an error to use this option in conjunction with the -l option.

      With nc yes I get O_O

  4.   eliotime3000 said

    And how do I connect to a VPS over SSL?

  5.   vidagnu said

    What I always do is run nmapfe host-ip so that it gives me all the tcp ports, now to see the open udp ports you have to run:

    nmap -sU host-ip

    I have also used telnet more than anything else on windows if I don't have nmap installed, the netcat variant does not appeal to me ...

    regards

  6.   Alejandro said

    I would like to know more about this, I hope you can support me, I have very basic knowledge and I would like to know more to apply this type of knowledge in my work.

  7.   tecnologia21 said

    I just discovered that I do not have the ports I need open, now I will have to research how to open them in order to do what I need. Thanks for the contribution, it has helped me a lot.

  8.   Domtrel said

    Very interesting article! Besides netcat, it also works on vmware ESXi:

    http://www.sysadmit.com/2015/09/prueba-de-conexion-un-puerto-desde-VMWare-Windows-Linux.html

  9.   lolo said

    sudo get install nmap

    nam 192.168.0.19 -p 21 | grep -i tcp

    home of local user srv / ftp

    restart with sudo service vsftpd restart

    write_enable = YES so that local users can upload files.

    To cage anonymous in his home
    chroot_local_user = yes
    chroot_list_enable = yes

    allow_writreable_chroot = yes

    no_annon_password = no for the anonymous to put pass as courtesy

    deny_email_enable = yes
    banned_email_file = / etc / vsftpd.banned_emails To deny an anonymous by email.
    ____————————————————————–
    cage user less than those on the list
    chroot_local_user = yes
    chroot_lits_enable = yes

    chroot_list_file = / etc / vsftpd.chroot_list.

    To add users sudo adduser name

    disable locales local_enable = no

    cage yourselves by default
    anonymous caged in srv / ftp

    premises in your home

  10.   dalisperis said

    Very good! If we don't have nmap, telnet or netcat, we can use cat and the proc directory:

    cat </ dev / tcp / HOST / PORT

    Example: http://www.sysadmit.com/2016/03/linux-cat-y-proc-prueba-de-conexion.html

  11.   cuetox said

    Thanks, very good explanation