Netcat confuses me a little bit and here are the reasons:
when I run:
nmap localhost There are some ports listed with the information whether they are open or closed. So if I run the command : nc -l -p 60000 and in an other terminal:
nmap localhost -p 60000
There will be the port 60000 listed and it says that it is open.
And if it stops to listen, it is closed. I thought the netcat listener was just listening and what I am understanding here is that it opens the specific port ?
And why is the port not listed when I run the nmap localhost command?
There are always just a few ports.

closed as unclear what you're asking by Rui F Ribeiro, meuh, X Tian, muru, telcoM May 24 at 6:08

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • Program listening on a port = port open. No program listening on a port = port closed. What's not to understand about this? Or rather, what exactly is the question here? – Panki May 17 at 11:25
  • I thought that you have to type in a command that opens the port. Didn't think about that if I listen to a port it opens automaticly – S. Yildiz May 17 at 12:32
  • Well, that depends if there is a firewall running on the system. – Panki May 17 at 13:06
  • 1
    As for your last question, form man nmap: By default, Nmap scans the most common 1,000 ports for each protocol., 60000 is probably not among these. – pLumo May 17 at 13:21
  • A basic firewall by itself can never open a closed port, but can definitely block a port so that it will never be open unless the firewall is reconfigured to unblock it. – telcoM May 24 at 6:08

A TCP port is just a number used as an address. To say that a port is "open" means that a process has registered with the OS for incoming connections on that port number, and that nothing between Nmap and the program is stopping the connection. The default state for a port is "closed," meaning that no process has registered with the OS for connections on that port, so the OS will reject any such connections.

When you start a netcat listener on port 60000, it is ready to accept one connection on that port. When you scan it with Nmap, the connection is accepted, so Nmap marks it as "open." But then the netcat listener quits because it has handled its one connection, so the next time the port will be marked "closed."

Traditional netcat can only ever handle one connection at a time. OpenBSD netcat and Ncat can accept multiple connections on the port by using the -k option.

You can avoid making a complete connection with Nmap by using the half-open TCP SYN scan option (-sS), which requires root privileges to use. In this case, Nmap stops short of making a complete connection, so the OS never informs netcat of the connection, and it does not quit. This is the default scan type for TCP scans with root privileges.

Not the answer you're looking for? Browse other questions tagged or ask your own question.