4

There are two flavors of netcat: netcat-openbsd and netcat-traditional.

How to know which flavor of netcat I'm using? I've tried man nc but it doesn't say what flavor it is.

8

First of all, you can install multiple flavors in your machine. So the answer depends on how many flavors you've installed and what command you type.

netcat-traditional and netcat-openbsd is available to be install via package manager apt in Ubuntu. In my case I also build from source to install GNU netcat flavor via this official website.

For "openbsd" flavor, you can figure out location binary name with dpkg -L <package-name> (Googling yourself to find equivalent of dpkg L if yor package manager is not apt):

$ dpkg -L netcat-openbsd | grep /bin
/bin
/bin/nc.openbsd

Then use type -a to confirm that binary name nc.openbsd is searchable in $PATH and interpreted as command:

$ type -a nc.openbsd
nc.openbsd is /bin/nc.openbsd
nc.openbsd is /bin/nc.openbsd

For "traditional" flavor is same:

$ dpkg -L netcat-traditional | grep /bin
/bin
/bin/nc.traditional
$ type -a nc.traditional
nc.traditional is /bin/nc.traditional
nc.traditional is /bin/nc.traditional

That's means I can issue command nc.openbsd to run netcat-openbsd tool, and also command nc.traditional to run netcat-traditional tool. (There may confuse where the command contains '.' but package name contains '-' )

Seems like there are 3 flavors to install via apt:

$ apt-cache search netcat --names-only
netcat-openbsd - TCP/IP swiss army knife
netcat - TCP/IP swiss army knife -- transitional package
netcat-traditional - TCP/IP swiss army knife

But actually netcat is dummy package only:

$ apt-cache show netcat | grep Description-en  -A 2
Description-en: TCP/IP swiss army knife -- transitional package
 This is a "dummy" package that depends on lenny's default version of
 netcat, to ease upgrades. It may be safely removed.

So you can only install netcat-openbsd and netcat-traditional via apt if you want:

sudo apt-get install netcat-openbsd
sudo apt-get install netcat-traditional

How about commands nc and netcat ? They can tied to multiple flavors searchable by $PATH, one of the path will run if you type nc or netcat. Again, you can use type -a to check, whereas priority is the first line (as bold below):

$ type -a nc 
nc is /usr/local/bin/nc
nc is /bin/nc
nc is /usr/local/bin/nc
nc is /bin/nc
$ type -a netcat
netcat is /usr/local/bin/netcat
netcat is /bin/netcat
netcat is /usr/local/bin/netcat
netcat is /bin/netcat

You can use realpath to figure out resolved path of them:

$ realpath /usr/local/bin/netcat 
/usr/local/bin/netcat
$ realpath /bin/netcat 
/bin/nc.openbsd
$ realpath /usr/local/bin/nc
/usr/local/bin/netcat
$ realpath /bin/nc
/bin/nc.openbsd

4 of them only 2 paths is unique in my system, one is "GNU", and the other one is "openbsd":

$ /usr/local/bin/netcat --version | head -1
netcat (The GNU Netcat) 0.7.1
$ /bin/nc.openbsd -h |& head -1
OpenBSD netcat (Debian patchlevel 1.130-3)

That's means if I type nc OR netcat, it will execute /usr/local/bin/netcat which is "GNU Netcat".

You can try update-alternatives to adjust the resolved symlink path:

$ realpath /bin/nc
/bin/nc.openbsd
$ realpath /bin/netcat
/bin/nc.openbsd
$ sudo update-alternatives --config nc
There are 2 choices for the alternative nc (providing /bin/nc).

  Selection    Path                 Priority   Status
------------------------------------------------------------
  0            /bin/nc.openbsd       50        auto mode
* 1            /bin/nc.openbsd       50        manual mode
  2            /bin/nc.traditional   10        manual mode

Press <enter> to keep the current choice[*], or type selection number: 2
update-alternatives: using /bin/nc.traditional to provide /bin/nc (nc) in manual mode
$ realpath /bin/nc
/bin/nc.traditional
$ realpath /bin/netcat
/bin/nc.traditional

It changed both /bin/nc and /bin/netcat resolved symlink¹ to /bin/nc.traditional, but still it doesn't changed the flavor if I type nc OR netcat since /usr/local/bin/ still has higher precedence over /bin in my $PATH:

$ /bin/nc -h |& head -1
[v1.10-41]
$ nc -h |& head -1
GNU netcat 0.7.1, a rewrite of the famous networking tool.
$ type -a nc | head -1
nc is /usr/local/bin/nc

Note that there are more flavors of netcat, e.g. ncat, socat, sbd, netcat6, pnetcat, and cryptcat.

¹ The actual symlink updated were /etc/alternatives/nc and /etc/alternatives/netcat, which /bin/nc and /bin/netcat were already symlink to /etc/alternatives/nc and /etc/alternatives/netcat respectively.

1

When I run nc --version, I get:

netcat (The GNU Netcat) 0.7.1
Copyright (C) 2002 - 2003  Giovanni Giacobbi

This program comes with NO WARRANTY, to the extent permitted by law.
You may redistribute copies of this program under the terms of
the GNU General Public License.
For more information about these matters, see the file named COPYING.

Original idea and design by Avian Research <hobbit@avian.org>,
Written by Giovanni Giacobbi <giovanni@giacobbi.net>.

Maybe the BSD version will say specifically as well.

  • Referencing another answer, what do you get for nc -h? – roaima Nov 30 '17 at 7:57
  • GNU netcat 0.7.1, a rewrite of the famous networking tool. followed by the help text. – John Moon Nov 30 '17 at 8:54
  • That's interesting. It seems that nc -h works in "both" versions, whereas nc --version works only for the GNU implementation. Thanks. – roaima Nov 30 '17 at 11:09
1

On a Mac (though it presents itself as the GNU version):

$ nc -h
GNU netcat 0.7.1, a rewrite of the famous networking tool.
[ further output snipped ]

On a Linux box (specifically Ubuntu):

$ nc -h
[v1.10-41]
[ further output snipped ]

netcat --version, suggested in another answer, threw an 'invalid option' error to --version, so -h seems to potentially be a universal test.

  • Does GNU netcat comes pre-installed with mac OS or did you install it yourself? – Joseph Nov 30 '17 at 21:59
  • I honestly do not recall, but the fact that it's in /usr/local/bin rather than /usr/bin implies I may have installed it with brew. – DopeGhoti Nov 30 '17 at 22:12
  • One last question if you don't mind, is the binary for GNU netcat called "netcat" and "nc" is just a link for "netcat"? (because I see here that the binary is called "netcat": fedora.pkgs.org/25/rpm-sphere/…). – Joseph Nov 30 '17 at 22:18
  • On my system, nc is just a symlink to netcat. You can check yourself with file $(which nc) which gives me /usr/bin/nc: symbolic link to netcat. – John Moon Dec 1 '17 at 0:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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