How can I select default version of Netcat in ubuntu

When I checked netcat -h I found out that the -e and Version option is missing from my netcat. I use Ubuntu 15.10. After searching from forums I found out a way to know the version installed and the candidate for it.

apt-cache policy netcat

I got the following output:

Installed: (none)
Candidate: 1.10-41
Version table:
1.10-41 0
500 http://archive.ubuntu.com/ubuntu/ wily/universe amd64 Packages

So I installed netcat and I got the candidate version. Now I'm confused about how to select the default netcat version and and -e option is nowhere to be seen.

What should be the solution for this?

Thanks.


Solution 1:

By default in Ubuntu netcat-openbsd package is installed. -e option is not available in netcat-openbsd. for that you need to install netcat-traditional package.

$sudo apt-get install netcat-traditional

After the installation you have to switch from netcat-openbsd to netcat-traditional. for that type

$sudo update-alternatives --config nc

you will get some choices like this

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: 

Then enter selection number of netcat-traditional in the prompt,( here 2 ).

and yes we done it.

to check does it work, type

$nc -h

you will see -e option in the list

Solution 2:

There is no installed version because netcat is a transitional package. It means it doesn't contain any files. The package installed (by default) and provides netcat is netcat-openbsd. You can check it's version:

apt-cache policy netcat-openbsd  

From netcat manual:

"There is no -c or -e option in this netcat, but you still can execute a command after connection being established by redirecting file descriptors. Be cautious here because opening a port and let anyone connected execute arbitrary command on your site is DANGEROUS (...)"


There is also netcat-traditional with -e option. You can remove netcat-openbsd and install traditional version:

sudo apt-get install netcat-traditional 

or keep both versions and choose traditional by running:

sudo update-alternatives --config nc