フィルタリングされたポートを開く方法

フィルタリングされたポートを開く方法

どういうわけか、UbuntuサーバーでSSHを停止し続け、理由を理解していません。私のddnsはmyserver.asuscomm.comに設定されており、ポートは私のルータから転送されます。そのうちの1つはうまく機能しますが、ddnsで接続すると、残りの2つはポートがフィルタリングされているように見えます。同じネットワークで接続すると、ポートが開いています。

私のルーターのいくつかの設定に問題がある可能性がありますか? SSHポートが22100であると仮定します。netstat -tlpnsshdがこのポートでリッスンしていることを示し、実行するとどこからでもトラフィックを許可できますsudo ufw status

同じネットワークで:

nmap -Pn -p 22100 192.168.50.x
Starting Nmap 7.80 ( https://nmap.org ) at 2021-10-01 10:13 CDT
Nmap scan report for 192.168.50.x
Host is up (0.00075s latency).

PORT      STATE SERVICE
22100/tcp open  optohost003

Nmap done: 1 IP address (1 host up) scanned in 0.13 seconds

ddnから切断します。

nmap -p 22100 myserver.asuscomm.com
Starting Nmap 7.80 ( https://nmap.org ) at 2021-10-01 10:14 CDT
Nmap scan report for myserver.asuscomm.com (x.y.z.123)
Host is up (0.025s latency).
rDNS record for x.y.z.123: c-x-y-z-123.abc.state.isp.net

PORT      STATE    SERVICE
22100/tcp filtered optohost003

Nmap done: 1 IP address (1 host up) scanned in 0.46 seconds

この特定のサーバーでは、標準nmapを実行したときにサーバーがダウンしていることが示されたため、-Pnフラグを追加する必要がありました。他のサーバーにも同じ問題がありますが、nmapは-Pn

この問題をどのように解決できるかを知っている人はいますか?ポートはすべて私のAsusルーターに転送され、変更できる他の設定が何であるかわかりません。別のポートでSSHを試す必要がありますか?


編集する:出力netstat -nlp(ポート22100は私のSSHです)

tcp        0      0 127.0.0.1:32401         0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:22100           0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.53:53           0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:32600         0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:41113         0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:445             0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:33060         0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:44935         0.0.0.0:*               LISTEN      -
tcp        0      0 192.168.50.7:27017      0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:27017         0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      -
tcp        0      0 0.0.0.0:139             0.0.0.0:*               LISTEN      -
tcp6       0      0 :::80                   :::*                    LISTEN      -
tcp6       0      0 :::32400                :::*                    LISTEN      -
tcp6       0      0 :::22100                :::*                    LISTEN      -
tcp6       0      0 :::445                  :::*                    LISTEN      -
tcp6       0      0 :::139                  :::*                    LISTEN      -
udp        0      0 127.0.0.53:53           0.0.0.0:*                           -
udp        0      0 192.168.50.7:68         0.0.0.0:*                           -
udp        0      0 172.17.255.255:137      0.0.0.0:*                           -
udp        0      0 172.17.0.1:137          0.0.0.0:*                           -
udp        0      0 192.168.50.255:137      0.0.0.0:*                           -
udp        0      0 192.168.50.7:137        0.0.0.0:*                           -
udp        0      0 0.0.0.0:137             0.0.0.0:*                           -
udp        0      0 172.17.255.255:138      0.0.0.0:*                           -
udp        0      0 172.17.0.1:138          0.0.0.0:*                           -
udp        0      0 192.168.50.255:138      0.0.0.0:*                           -
udp        0      0 192.168.50.7:138        0.0.0.0:*                           -
udp        0      0 0.0.0.0:138             0.0.0.0:*                           -
udp        0      0 127.0.0.1:33564         0.0.0.0:*                           -
udp        0      0 0.0.0.0:46034           0.0.0.0:*                           -
udp        0      0 0.0.0.0:5353            0.0.0.0:*                           -
udp        0      0 127.0.0.1:42818         0.0.0.0:*                           -
udp        0      0 0.0.0.0:51011           0.0.0.0:*                           -
udp        0      0 0.0.0.0:1901            0.0.0.0:*                           -
udp        0      0 192.168.50.7:38951      0.0.0.0:*                           -
udp        0      0 0.0.0.0:40101           0.0.0.0:*                           -
udp        0      0 0.0.0.0:32410           0.0.0.0:*                           -
udp        0      0 0.0.0.0:32412           0.0.0.0:*                           -
udp        0      0 0.0.0.0:32413           0.0.0.0:*                           -
udp        0      0 0.0.0.0:32414           0.0.0.0:*                           -
udp        0      0 192.168.50.7:57195      0.0.0.0:*                           -
udp        0      0 192.168.50.7:57254      0.0.0.0:*                           -
udp6       0      0 :::49275                :::*                                -
udp6       0      0 :::5353                 :::*                                -
raw6       0      0 :::58                   :::*                    7           -

出力sudo iptables -nvL

Chain INPUT (policy DROP 4793 packets, 1589K bytes)
 pkts bytes target     prot opt in     out     source               destination
 666K  472M ufw-before-logging-input  all  --  *      *       0.0.0.0/0            0.0.0.0/0
 666K  472M ufw-before-input  all  --  *      *       0.0.0.0/0            0.0.0.0/0
 262K   63M ufw-after-input  all  --  *      *       0.0.0.0/0            0.0.0.0/0
 155K   51M ufw-after-logging-input  all  --  *      *       0.0.0.0/0            0.0.0.0/0
 155K   51M ufw-reject-input  all  --  *      *       0.0.0.0/0            0.0.0.0/0
 155K   51M ufw-track-input  all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DOCKER-USER  all  --  *      *       0.0.0.0/0            0.0.0.0/0
    0     0 DOCKER-ISOLATION-STAGE-1  all  --  *      *       0.0.0.0/0            0.0.0.0/0
    0     0 ACCEPT     all  --  *      docker0  0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
    0     0 DOCKER     all  --  *      docker0  0.0.0.0/0            0.0.0.0/0
    0     0 ACCEPT     all  --  docker0 !docker0  0.0.0.0/0            0.0.0.0/0
    0     0 ACCEPT     all  --  docker0 docker0  0.0.0.0/0            0.0.0.0/0
    0     0 ufw-before-logging-forward  all  --  *      *       0.0.0.0/0            0.0.0.0/0
    0     0 ufw-before-forward  all  --  *      *       0.0.0.0/0            0.0.0.0/0
    0     0 ufw-after-forward  all  --  *      *       0.0.0.0/0            0.0.0.0/0
    0     0 ufw-after-logging-forward  all  --  *      *       0.0.0.0/0            0.0.0.0/0
    0     0 ufw-reject-forward  all  --  *      *       0.0.0.0/0            0.0.0.0/0
    0     0 ufw-track-forward  all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
 212K   16M ufw-before-logging-output  all  --  *      *       0.0.0.0/0            0.0.0.0/0
 212K   16M ufw-before-output  all  --  *      *       0.0.0.0/0            0.0.0.0/0
44581 3006K ufw-after-output  all  --  *      *       0.0.0.0/0            0.0.0.0/0
44581 3006K ufw-after-logging-output  all  --  *      *       0.0.0.0/0            0.0.0.0/0
44581 3006K ufw-reject-output  all  --  *      *       0.0.0.0/0            0.0.0.0/0
44581 3006K ufw-track-output  all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain DOCKER (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain DOCKER-ISOLATION-STAGE-1 (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DOCKER-ISOLATION-STAGE-2  all  --  docker0 !docker0  0.0.0.0/0            0.0.0.0/0
    0     0 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain DOCKER-ISOLATION-STAGE-2 (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DROP       all  --  *      docker0  0.0.0.0/0            0.0.0.0/0
    0     0 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain DOCKER-USER (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain ufw-after-forward (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw-after-input (1 references)
 pkts bytes target     prot opt in     out     source               destination
  326 26112 ufw-skip-to-policy-input  udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:137
  730  180K ufw-skip-to-policy-input  udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:138
    2    88 ufw-skip-to-policy-input  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:139
    2    88 ufw-skip-to-policy-input  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:445
   27  8992 ufw-skip-to-policy-input  udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:67
    0     0 ufw-skip-to-policy-input  udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:68
 106K   11M ufw-skip-to-policy-input  all  --  *      *       0.0.0.0/0            0.0.0.0/0            ADDRTYPE match dst-type BROADCAST

Chain ufw-after-logging-forward (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0            limit: avg 3/min burst 10 LOG flags 0 level 4 prefix "[UFW BLOCK] "

Chain ufw-after-logging-input (1 references)
 pkts bytes target     prot opt in     out     source               destination
 4337 1529K LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0            limit: avg 3/min burst 10 LOG flags 0 level 4 prefix "[UFW BLOCK] "

Chain ufw-after-logging-output (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw-after-output (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw-before-forward (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 3
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 11
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 12
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 8
    0     0 ufw-user-forward  all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain ufw-before-input (1 references)
 pkts bytes target     prot opt in     out     source               destination
40237 2361K ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0
 308K  387M ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
    0     0 ufw-logging-deny  all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate INVALID
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate INVALID
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 3
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 11
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 12
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0            icmptype 8
    0     0 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp spt:67 dpt:68
 318K   82M ufw-not-local  all  --  *      *       0.0.0.0/0            0.0.0.0/0
 1987  325K ACCEPT     udp  --  *      *       0.0.0.0/0            224.0.0.251          udp dpt:5353
53945   19M ACCEPT     udp  --  *      *       0.0.0.0/0            239.255.255.250      udp dpt:1900
 262K   63M ufw-user-input  all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain ufw-before-logging-forward (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw-before-logging-input (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw-before-logging-output (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw-before-output (1 references)
 pkts bytes target     prot opt in     out     source               destination
40237 2361K ACCEPT     all  --  *      lo      0.0.0.0/0            0.0.0.0/0
 128K   11M ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
44581 3006K ufw-user-output  all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain ufw-logging-allow (0 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0            limit: avg 3/min burst 10 LOG flags 0 level 4 prefix "[UFW ALLOW] "

Chain ufw-logging-deny (2 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate INVALID limit: avg 3/min burst 10
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0            limit: avg 3/min burst 10 LOG flags 0 level 4 prefix "[UFW BLOCK] "

Chain ufw-not-local (1 references)
 pkts bytes target     prot opt in     out     source               destination
 151K   51M RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ADDRTYPE match dst-type LOCAL
60270   19M RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ADDRTYPE match dst-type MULTICAST
 107K   12M RETURN     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ADDRTYPE match dst-type BROADCAST
    0     0 ufw-logging-deny  all  --  *      *       0.0.0.0/0            0.0.0.0/0            limit: avg 3/min burst 10
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain ufw-reject-forward (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw-reject-input (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw-reject-output (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw-skip-to-policy-forward (0 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain ufw-skip-to-policy-input (7 references)
 pkts bytes target     prot opt in     out     source               destination
 107K   12M DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain ufw-skip-to-policy-output (0 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain ufw-track-forward (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw-track-input (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw-track-output (1 references)
 pkts bytes target     prot opt in     out     source               destination
  173 10348 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate NEW
44407 2995K ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate NEW

Chain ufw-user-forward (1 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw-user-input (1 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     tcp  --  *      *       73.6.251.121         0.0.0.0/0            tcp dpt:27017
    0     0 ACCEPT     udp  --  *      *       73.6.251.121         0.0.0.0/0            udp dpt:27017
   53  2812 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:22001
    6   360 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:22000
    3   132 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:21
    6   344 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:22100

Chain ufw-user-limit (0 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 LOG        all  --  *      *       0.0.0.0/0            0.0.0.0/0            limit: avg 3/min burst 5 LOG flags 0 level 4 prefix "[UFW LIMIT BLOCK] "
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-port-unreachable

Chain ufw-user-limit-accept (0 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0

Chain ufw-user-logging-forward (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw-user-logging-input (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw-user-logging-output (0 references)
 pkts bytes target     prot opt in     out     source               destination

Chain ufw-user-output (1 references)
 pkts bytes target     prot opt in     out     source               destination

iptables -t nat -nvL:

Chain PREROUTING (policy ACCEPT 35687 packets, 8678K bytes)
 pkts bytes target     prot opt in     out     source               destination
 4099 1364K DOCKER     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ADDRTYPE match dst-type LOCAL

Chain INPUT (policy ACCEPT 6440 packets, 1931K bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 3131 packets, 314K bytes)
 pkts bytes target     prot opt in     out     source               destination
    1   278 DOCKER     all  --  *      *       0.0.0.0/0           !127.0.0.0/8          ADDRTYPE match dst-type LOCAL

Chain POSTROUTING (policy ACCEPT 3131 packets, 314K bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 MASQUERADE  all  --  *      !docker0  172.17.0.0/16        0.0.0.0/0

Chain DOCKER (2 references)
 pkts bytes target     prot opt in     out     source               destination
    0     0 RETURN     all  --  docker0 *       0.0.0.0/0            0.0.0.0/0

iptables -t mangle -nvL:

Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

別の編集: 他にも最後にvar/log/syslog興味深い点を確認して発見しました。 ufwが私のルーターからサーバーへの接続をブロックしているということです。

Oct  1 16:36:00 user kernel: [   71.994434] [UFW BLOCK] IN=eth0 OUT= MAC=mac_address_here SRC=192.168.50.1 DST=192.168.50.7 LEN=386 TOS=0x00 PREC=0x00 TTL=64 ID=49481 PROTO=UDP SPT=1900 DPT=56241 LEN=366 

ufw私は192.168.50.1から入って来るトラフィックを許可するように設定しましたが、サイコロはありません。よく…

ベストアンサー1

myserver.asuscomm.com私たちは、ルーターがあなたのサーバーを指し、ルーターがポートをサーバーに正しく転送することを前提としています。

サービスはループバックまたはLANアドレスで受信して有効にできますが、他の場所では使用できません。これはあなたが見ていることを証明するようです。

だから見なければならないのは、

  • ポートは何を受信して​​いますか?
  • これらのサービスはどのインターフェイス/アドレスを受信して​​いますか?
  • どのファイアウォールルールを実装しましたか?
  • どのアプリケーションレベルの接続ルールを実装しましたか?

これらのうちの最初の2つは、次のコマンドで表示できますnetstat -nlp。質問に以下の詳細を提供しました。

Proto Recv-Q Send-Q Local Address  Foreign Address  State   PID/Program name
tcp        0      0 0.0.0.0:22100  0.0.0.0:*        LISTEN  -
tcp6       0      0 :::22100       :::*             LISTEN  -

これは、ポート22100のサービスがすべてのインターフェイス(0.0.0.0および::すべての着信トラフィック)をリッスンしていることを確認します。

iptables実装されたファイアウォールルールは、次のコマンドを使用して確認できます(nftablesあなたが使用している場合は直接助けることはできません)。

iptables -nvL
iptables -t nat -nvL
iptables -t mangle -nvL

質問に追加した出力を見ると、ACCEPTUFWファイアウォールルールセットにポート22100へのインバウンドTCPトラフィックを許可するルールがあることがわかります。

Chain ufw-user-input (1 references)
 pkts bytes target     prot opt in     out     source               destination
  […]
    6   344 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:22100

アプリケーションレベルの接続ルールは通常、および/etc/hosts.allow/またはで定義されていますが、アプリケーション固有の設定ファイル(例)/etc/hosts.denyにもあります。/etc/ssh/sshd_config

ここではサーバー設定に問題はありませんので、もう一度確認してみましょう。

  • 正しいポートを使用して外部から正しいIPアドレスに接続しています(いくつかの例ではportを、1234他の例はportを表示します22100)。
  • ISPはこのポートで着信TCP / IPトラフィックを許可します。
  • ルータのポート転送が実際に正しく設定されています。

ところで、用語の問題が発生する可能性があります。 」ddnsで接続すると「本当に言うことはできません。接続できません。」~から「DDNSはドメイン名を(動的)IPアドレスに変換するサービスだけですから。 おっしゃると思います」ネットワーク外でDDNS経由で確認されたIPアドレスに接続する場合」。

おすすめ記事