netcat - keep listening for connection in Debian

23

4

There's -k option in OS X (BSD) version of netcat to keep listening after current connection is completed. However in Debian (GNU?) version this option is missing.

There's -q -1 option to listen forever after EOF appears on stdin but this doesn't do the trick and connections close anyway.

Is there any way to force Debian's netcat to keep listening indefinitely?

Peta Sittek

Posted 2015-12-02T23:14:54.063

Reputation: 488

Answers

30

Debian's implementation of Netcat does have the -k option. However, it's not documented in the manual because it doesn't work in a reliable manner, for some unknown reason.

Luckily, there's ncat, which is yet another implementation of Netcat and is part of the nmap package. This one has a working -k. You can get it by installing nmap. ncat's options and usage are more or less similar to other implementations of Netcat, so your knowledge of other implementations should transfer very well to ncat.

Larssend

Posted 2015-12-02T23:14:54.063

Reputation: 2 941

1Thank you! Thanks to you I found best version of netcat ever. – Aalex Gabi – 2017-10-20T20:04:25.917

1openbsd-netcat appears to have the -k option as well – Andrew Savinykh – 2018-06-19T05:01:18.407

Package is netcat-openbsd, not openbsd-netcat for those who might not click @AndrewSavinykh link – Robin Thoni – 2019-04-08T22:22:59.990