-l Used to specify that nc should listen for an incoming connection rather than initiate a connection to a remote host. It is an error to use this option in conjunction with the -p, -s, or -z options. Additionally, any timeouts specified with the -w option are ignored.
The key here is that -p cannot be combined with the -l flag. When using the -l flag, any ports specified in the positional arguments are used. So instead, you could use the following:
For some reason, Andrew's solution didn't work for me. With further research, I learned that we need to add -p flag when working locally. So the following command worked for me.
To quote the
nc
man page:The key here is that
-p
cannot be combined with the-l
flag. When using the-l
flag, any ports specified in the positional arguments are used. So instead, you could use the following:-p
is wrong. This will work on RedHat- and Debian-based distros:For some reason, Andrew's solution didn't work for me. With further research, I learned that we need to add -p flag when working locally. So the following command worked for me.