一、情况
出现以下情况:
[Jay@localhost001 ~]$ nc
Ncat: You must specify a host to connect to. QUITTING.
或是
[Jay@localhost002 ~]$ nc localhost001 9999
Ncat: Connection refused.
那么你的情况和博主的一样,下面是解决方案。
二、原因
在CentOS6.4中使用yum install -y nc
安装的是nc命令(netcat);
在CentOS7.X中使用yum install -y nc
安装的并不是netcat而是nmap-ncat,并且通过软链接的方式链接为nc命令,但实际是ncat命令;
nc
与netcat
通常是一个东西,而ncat
(也称nmap-ncat
)是另一个东西,默认的nc
命令链接到了ncat
,所以自然得不到我们想要的结果。
[Jay@localhost001 ~]$ whereis nc
nc: /usr/bin/nc /usr/share/man/man1/nc.1.gz
[Jay@localhost001 ~]$ ls -l /usr/bin/nc
lrwxrwxrwx. 1 root root 22 10月 31 21:17 /usr/bin/nc -> /etc/alternatives/nmap
通过上面的指令,可以看到nc链接的是/etc/alternatives/nmap,并不是netcat,所以遇到这种情况大概率是没有安装过netcat,安装一下就行,然后再将nc链接到netcat就行了;
三、解决方法
- 首先:使用rm /usr/bin/nc删除原软链接
[Jay@localhost001 ~]$ sudo rm /usr/bin/nc [Jay@localhost001 ~]$ whereis nc nc: /usr/share/man/man1/nc.1.gz
- 下载netcat
[Jay@localhost001 ~]$ wget https://sourceforge.net/projects/netcat/files/netcat/0.7.1/netcat-0.7.1.tar.gz --no-check-certificate
如果使用wget安装netcat时,出现-bash: wget: 未找到命令,那说明你需要安装一下wget;
[Jay@loacalhost001 ~]$ sudo yum install -y wget
安装完wget后,重新下载netcat;
-
解压netcat-0.7.1.tar.gz,并编译
[Jay@localhost001 ~]$ ll -rw-rw-r--. 1 Jay Jay 398872 1月 12 2004 netcat-0.7.1.tar.gz [Jay@localhost001 ~]$ tar -zxf netcat-0.7.1.tar.gz [Jay@localhost001 ~]$ ll drwxrwxr-x. 7 Jay Jay 4096 1月 12 2004 netcat-0.7.1
解压完成后,还需要对netcat-0.7.1进行编译;
[Jay@localhost001 ~]$ cd netcat-0.7.1 [Jay@localhost001 netcat-0.7.1]$ ./configure
如果在netcat-0.7.1目录下执行./configure后出现以下信息
checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... x86_64-unknown-linux-gnu checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes checking for gawk... gawk checking whether make sets $(MAKE)... yes checking for gcc... no checking for cc... no checking for cc... no checking for cl... no configure: error: no acceptable C compiler found in $PATH See `config.log' for more details.
说明你还需要安装gcc编译器;
[Jay@localhost001 netcat-0.7.1]$ yum install -y gcc
重新在netcat-0.7.1目录下执行./configure命令,等./configure命令执行完成之后,并接着在netcat-0.7.1目录下执行sudo make和sudo make install命令;
[Jay@localhost001 netcat-0.7.1]$ ./configure checking build system type... x86_64-unknown-linux-gnu checking host system type... x86_64-unknown-linux-gnu checking target system type... x86_64-unknown-linux-gnu checking for a BSD-compatible install... /usr/bin/install -c checking whether build environment is sane... yes ........ ........ [Jay@localhost001 netcat-0.7.1]$ sudo make make all-recursive make[1]: 进入目录“/home/Jay/netcat-0.7.1” Making all in m4 make[2]: 进入目录“/home/Jay/netcat-0.7.1/m4” make[2]: 对“all”无需做任何事。 make[2]: 离开目录“/home/Jay/netcat-0.7.1/m4” Making all in lib make[2]: 进入目录“/home/Jay/netcat-0.7.1/lib” Making all in contrib ......... ......... [Jay@localhost001 netcat-0.7.1]$ sudo make install Making install in m4 make[1]: 进入目录“/home/Jay/netcat-0.7.1/m4” make[2]: 进入目录“/home/Jay/netcat-0.7.1/m4” make[2]: 对“install-exec-am”无需做任何事。 make[2]: 对“install-data-am”无需做任何事。 ....... .......
等指令执行完之后,可以看到/usr/local/bin目录下回产生一些东西
[Jay@localhost001 netcat-0.7.1]$ cd /usr/local/bin
[Jay@localhost001 bin]$ ll
总用量 124
lrwxrwxrwx. 1 root root 6 10月 31 22:16 nc -> netcat
-rwxr-xr-x. 1 root root 126808 10月 31 22:16 netcat
4.在/usr/bin目录下创建一个新的nc链接,这个nc链接向/usr/local/bin下的nc
[Jay@localhost001 ~]$ sudo ln -s /usr/local/bin/nc /usr/bin/nc
注意:一定要先将/usr/bin目录下原先的uc链接(/usr/bin/nc -> /etc/alternatives/nmap)删掉。
5.正常使用
[Jay@localhost001 ~]$ nc
Cmd line:
参考资料:
解决centos使用nc命令报错:Ncat: Connection refused.
linux:centos报错checking build system type... x86_64-unknown-linux-gnu