CentOS7のncコマンドとiptables

CentOS7のncコマンドとiptables

私は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ポートを開こうとしましたが、コマンドが中断されました。インターネットを見てみると、この記事でiptablesルールを更新できることがわかりました。netcatコマンドが開いているポートにアクセスできません。しかし、それ以降はインターネットにまったく接続できません。それで、私は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ポートを開くにはどうすればよいですか?

ベストアンサー1

コメントに記載されている - 最も重要な事項の簡単な要約:

  • ncatそして、着信接続を一度だけ受信し、最初の試みでそれを停止する他のnetcat実装も可能です(プログラムにスイッチがない場合)。

  • プログラムは、現在のiptables設定に関係なく、ポートでリッスンを開始できます。

おすすめ記事