我已经在CentOS 7(在Virtual Box上是客户机)上使用iptables进行了练习。起初我禁用了firewalld
:
systemctl disable firewalld
systemctl stop firewalld
然后我安装了iptables:
yum -y install iptables-services
systemctl enable iptables
systemctl start iptables
完成所有这些操作后,我尝试使用nc -l 1025
命令在本地计算机上打开tcp-port,但命令只是挂断了。我在整个Internet上查找,发现可以在这篇文章中刷新iptables规则netcat命令无法访问打开的端口,但是此后我根本没有连接到Internet。因此,当我刚安装iptables时,我将CentOS7恢复为以前的状态。这是我的iptables的规则:
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT icmp -- anywhere anywhere
ACCEPT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain FORWARD (policy ACCEPT)
target prot opt source destination
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
这是的详细模式nc -vl 1025
:
Ncat: Version 6.40 ( http://nmap.org/ncat )
Ncat: Listening on :::1025
Ncat: Listening on 0.0.0.0:1025
和的结果ss -lnt
:
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
例如端口2000的另一种详细模式nc -vl 2000
:
Ncat: Version 6.40 ( http://nmap.org/ncat )
Ncat: Listening on :::2000
Ncat: Listening on 0.0.0.0:2000
的结果ss -lnt
是相同的:
State Recv-Q Send-Q Local Address:Port Peer Address:Port
LISTEN 0 128 *:22 *:*
LISTEN 0 100 127.0.0.1:25 *:*
LISTEN 0 128 :::22 :::*
LISTEN 0 100 ::1:25 :::*
因此,我该怎么做才能使nc
命令正常工作,并可以在CentOS7上打开一些tcp端口?
在评论中得到解决-最重要的要点快速总结:
ncat
以及可能的其他netcat
实现方式,仅侦听一次传入的连接,并在第一次尝试时停止这样做(除非程序中对此进行了切换)
程序可以开始在端口上侦听,而不管当前的iptables设置是什么
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句