如何在Ubuntu中选择Netcat的默认版本

当我检查netcat -h时,我发现我的netcat中缺少-eVersion选项。我使用的是Ubuntu 15.10。 在论坛上搜索后,我找到了一种了解安装版本和候选版本的方法。
apt-cache policy netcat

我得到了以下的输出:
Installed: (none)
Candidate: 1.10-41
Version table:
1.10-41 0
500 http://archive.ubuntu.com/ubuntu/ wily/universe amd64 Packages

我安装了netcat并获得了候选版本。现在我对如何选择默认的netcat版本感到困惑,而-e选项则无处可见。

这个问题应该怎么解决?

谢谢。


嗨EdiD,谢谢。它有效了。我将我的netcat更改为netcat-traditional。 - Harshit Garg
2个回答

默认情况下,在Ubuntu中安装了netcat-openbsd软件包。在netcat-openbsd中,没有提供-e选项。如果需要该选项,您需要安装netcat-traditional软件包。
$sudo apt-get install netcat-traditional

安装之后,你需要从netcat-openbsd切换到netcat-traditional。要进行切换,请输入以下命令:
$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: 

然后在提示符中输入netcat-traditional的选择号码(这里是2)。

是的,我们做到了。

为了检查它是否工作,请键入

$nc -h

你会在列表中看到-e选项。

如果你需要在脚本中执行这个操作,可以使用命令 update-alternatives --set nc /bin/nc.traditional - A Kingscote

没有安装版本,因为netcat是一个过渡包。这意味着它不包含任何文件。 默认安装并提供netcat的软件包是netcat-openbsd。您可以检查其版本:
apt-cache policy netcat-openbsd  

从netcat手册中:
"在这个netcat版本中,没有-c或-e选项,但是你仍然可以通过重定向文件描述符,在连接建立后执行命令。在这里要小心,因为打开一个端口并允许任何人连接并在你的站点上执行任意命令是危险的..."
还有一个带有-e选项的netcat-traditional。您可以移除netcat-openbsd并安装传统版本:
sudo apt-get install netcat-traditional 

或者保留两个版本并选择繁体版,方法是运行:

sudo update-alternatives --config nc