在路由器中使用firewall-cmd打开某些端口后,无法对某些端口进行ncat

在路由器中使用firewall-cmd打开某些端口后,无法对某些端口进行ncat

我想在 Fedora 32 服务器上打开一些端口,包括 UDP 和 TCP。

首先,我在路由器上打开它们,然后重新启动路由器:

路由器配置

然后,我将它们打开firewalld

sudo firewall-cmd --permanent --add-port=5000/tcp
sudo firewall-cmd --permanent --add-port=5000/udp
sudo firewall-cmd --permanent --add-port=2022/tcp
sudo firewall-cmd --permanent --add-port=2022/udp
sudo firewall-cmd --reload

nc在另一台电脑上使用,ping服务器,只有其中一个是开放的,即TCP 2022:

$ nc -z -v -u $FTDB 5000                                                                                                                                                   (base) 324ms
Ncat: Version 7.80 ( https://nmap.org/ncat )
Ncat: Connected to XXXX
Ncat: Connection refused.
$ nc -z -v $FTDB 5000                                                                                                                                                      (base) 333ms
Ncat: Version 7.80 ( https://nmap.org/ncat )
Ncat: Connection refused.
$ nc -z -v $FTDB 2022                                                                                                                                                      (base) 347ms
Ncat: Version 7.80 ( https://nmap.org/ncat )
Ncat: Connected to XXXX
Ncat: 0 bytes sent, 0 bytes received in 0.34 seconds.
$ nc -z -v -u $FTDB 2022                                                                                                                                                        (base) 
Ncat: Version 7.80 ( https://nmap.org/ncat )
Ncat: Connected to XXXX
Ncat: Connection refused.

其他信息:

firewall-cmd

sudo firewall-cmd --list-all                                                                                                                                     (base) 
FedoraWorkstation (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens5
  sources: 
  services: cockpit dhcpv6-client dns dns-over-tls docker-registry et https mdns mosh openvpn samba-client ssh
  ports: 1025-65535/udp 1025-65535/tcp 60000/udp 60001/udp 5000/udp 5000/tcp 2022/tcp 2022/udp 12345/udp 12345/tcp 12346/tcp 12346/udp 12347/tcp 12347/udp 9090/tcp 9090/udp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

ss:

ss -tulpn | grep '5000\|2022'                                                                                                                                    (base) 
tcp   LISTEN 0      32                             0.0.0.0:2022       0.0.0.0:*                                              
tcp   LISTEN 0      128                          127.0.0.1:5000       0.0.0.0:*    users:(("python",pid=3206,fd=65))         
tcp   LISTEN 0      32                                [::]:2022          [::]:*    

ifconfig:

ifconfig | grep -A 1 'ens5'                                                                                                                                      (base) 
ens5: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.2.101  netmask 255.255.255.0  broadcast 192.168.2.255

netstat:

netstat -lntu  | grep '5000\|2022'                                                                                                                               (base) 
tcp        0      0 0.0.0.0:2022            0.0.0.0:*               LISTEN     
tcp        0      0 127.0.0.1:5000          0.0.0.0:*               LISTEN     
tcp6       0      0 :::2022                 :::*                    LISTEN   

答案1

问题是 TCP 服务正在服务器上的端口 2022 上运行,但在 5000 上运行的服务仅绑定到 127.0.0.1。该特定服务是 Flask socketio 应用程序。我将代码更改为socketio.run(app, host="0.0.0.0", port=5000).

相关内容