In the manpage for nc -l
, it says:
It is an error to use this option in conjunction with the -p, -s, or -z options.
But most examples I see online using this command use nc -lp [port]
.
Can you use -p
with -l
in nc
? And with just nc -l [port]
, is that the correct usage of it because when I connect to it on another terminal with nc [ip address] [port]
, it works. Also, when I use nc -lp [port]
and connect to it with nc [ip address] [port]
, it also works. Is there a difference between these two commands?
Note that there are two netcat packages. And the options are not the same for the
nc
commands they provide:netcat-traditional shows this command as one of the main examples:
While netcat-openbsd states:
So yes, both commands do the same, but you might run into examples that do not work with your version of netcat. For example
-e
.When you are using the listen mode
-l
you must specify port. For example:So actually you do not need an additional option like
-p
to instruct thenc
command at which port to listen. The examples that uses-lp
option probably are based on an old version ofnc
or the writers didn't read the manual like you :) Also probably when the-lp
combination is used the-p
option is just omitted.In addition, here is how to create a listen service, based on
nc
: How to listen new port Ubuntu Server from command line?