如何配置 netcat(或其他一些股票 linux 实用程序)以侦听辅助 IP 地址上的特定端口?

Mik*_*e B 19 linux netcat centos5

CentOS 5.9

出于测试目的,我希望我的 CentOS 服务器侦听辅助虚拟 IP (eth0:0)。我很熟悉,nc -l -p <port>但它只听初级。有没有办法可以指定特定的 IP 供侦听器使用?

如果没有,CentOS 5.9 中是否有另一个“库存”实用程序可以做到这一点?

Hau*_*ing 35

语法取决于netcat包。

netcat-openbsd

nc -l 192.168.2.1 3000
Run Code Online (Sandbox Code Playgroud)

netcat-传统

nc -l -p 3000 -s 192.168.2.1
Run Code Online (Sandbox Code Playgroud)

在脚本中区分它们的一种简单方法(至少在 bash 中)是:

if ldd $(type -P nc) | grep -q libbsd; then
    nc -l 192.168.2.1 3000
else
    nc -l -p 3000 -s 192.168.2.1
fi
Run Code Online (Sandbox Code Playgroud)


sch*_*cht 8

完成:

nc -l -p 端口 -s ip

也应该工作。适用于 nc6 1.0 版和 netcat(GNU Netcat)0.7.1。

来自 Laging 的命令不适用于 nc6(在 debian 中使用)。

  • 我可以在 Ubuntu 的 `nc` 上指定监听接口的唯一方法。 (2认同)
  • nc 说你不能同时使用 -s 和 -l (2认同)