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.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
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-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
$ dpkg -L netcat-openbsd | grep /bin /bin /bin/nc.openbsd
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-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
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
apt if you want:
sudo apt-get install netcat-openbsd sudo apt-get install netcat-traditional
How about commands
netcat ? They can tied to multiple flavors searchable by
$PATH, one of the path will run if you type
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
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/netcat resolved symlink¹ to
/bin/nc.traditional, but still it doesn't changed the flavor if I type
/usr/local/bin/ still has higher precedence over
/bin in my
$ /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
¹ The actual symlink updated were
/bin/netcat were already symlink to
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 <email@example.com>, Written by Giovanni Giacobbi <firstname.lastname@example.org>.
Maybe the BSD version will say specifically as well.
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
-h seems to potentially be a universal test.