なぜfirewalldはドロップルールを適用しないのですか?

なぜfirewalldはドロップルールを適用しないのですか?

CentOS 7 では、ソース IP (例 3.3.3.3) からのトラフィックをブロックしたいので、次のルールを適用します。

# firewall-cmd --permanent --zone=drop --add-source=3.3.3.0/24
# firewall-cmd --reload

このコマンドを実行した後、次のようにルールが適用されていることを確認しました。

firewall-cmd --list-all --zone=drop
drop (active)
  target: DROP
  icmp-block-inversion: no
  interfaces: 
  sources: 3.3.3.0/24
  services: 
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

ここでは、他のすべてのアクティブなルールの出力を確認できます。

firewall-cmd --list-all --zone=public
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eno4
  sources: 
  services: dhcpv6-client ssh
  ports: 5060/udp 16384-32768/udp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules:

firewall-cmd --list-all --zone=internal
internal (active)
  target: default
  icmp-block-inversion: no
  interfaces: eno1
  sources: 
  services: mdns dhcpv6-client samba-client ssh
  ports: 80/tcp 60024/tcp 5080/udp 8080/tcp 5060/tcp 161/udp 5080/tcp 5060/udp 16384-32768/udp
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

ルート テーブルでは、3.3.3.0/24 のトラフィックをルーティングするパブリック ゾーンがリストされます。

ip route
default via 1.1.1.1 dev eno4 
10.1.1.0/24 via 10.1.1.1 dev eno1 

つまり、そのルールは適用されていますが、Centos マシンのリッスン ポート (5060) でこのソース IP からのトラフィック (UDP) が引き続き受信されます。ルールの何が問題なのでしょうか?

アップデート マイケルが言ったように、iptables -nvLの出力があります

iptables -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination         
  46M   33G ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED
53342 3122K ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
 315K   35M INPUT_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
 315K   35M INPUT_ZONES_SOURCE  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
 315K   35M INPUT_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
   85  3916 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate INVALID
 1908 87293 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 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     all  --  lo     *       0.0.0.0/0            0.0.0.0/0           
    0     0 FORWARD_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 FORWARD_IN_ZONES_SOURCE  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 FORWARD_IN_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 FORWARD_OUT_ZONES_SOURCE  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 FORWARD_OUT_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate INVALID
    0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

Chain OUTPUT (policy ACCEPT 46M packets, 21G bytes)
 pkts bytes target     prot opt in     out     source               destination         
  46M   21G OUTPUT_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain FORWARD_IN_ZONES (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 FWDI_public  all  --  eno4   *       0.0.0.0/0            0.0.0.0/0           [goto] 
    0     0 FWDI_internal  all  --  eno1   *       0.0.0.0/0            0.0.0.0/0           [goto] 
    0     0 FWDI_public  all  --  +      *       0.0.0.0/0            0.0.0.0/0           [goto] 

Chain FORWARD_IN_ZONES_SOURCE (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 FWDI_drop  all  --  *      *       3.3.3.0/24       0.0.0.0/0           
    0     0 FWDI_drop  all  --  *      *       3.3.3.0/24       0.0.0.0/0           

Chain FORWARD_OUT_ZONES (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 FWDO_public  all  --  *      eno4    0.0.0.0/0            0.0.0.0/0           [goto] 
    0     0 FWDO_internal  all  --  *      eno1    0.0.0.0/0            0.0.0.0/0           [goto] 
    0     0 FWDO_public  all  --  *      +       0.0.0.0/0            0.0.0.0/0           [goto] 

Chain FORWARD_OUT_ZONES_SOURCE (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 FWDO_drop  all  --  *      *       0.0.0.0/0            3.3.3.0/24      
    0     0 FWDO_drop  all  --  *      *       0.0.0.0/0            3.3.3.0/24      

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

Chain FWDI_drop (2 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 FWDI_drop_log  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 FWDI_drop_deny  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 FWDI_drop_allow  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           

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

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

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

Chain FWDI_internal (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 FWDI_internal_log  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 FWDI_internal_deny  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 FWDI_internal_allow  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           

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

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

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

Chain FWDI_public (2 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 FWDI_public_log  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 FWDI_public_deny  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 FWDI_public_allow  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           

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

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

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

Chain FWDO_drop (2 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 FWDO_drop_log  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 FWDO_drop_deny  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 FWDO_drop_allow  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           

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

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

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

Chain FWDO_internal (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 FWDO_internal_log  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 FWDO_internal_deny  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 FWDO_internal_allow  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

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

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

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

Chain FWDO_public (2 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 FWDO_public_log  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 FWDO_public_deny  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 FWDO_public_allow  all  --  *      *       0.0.0.0/0            0.0.0.0/0           

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

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

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

Chain INPUT_ZONES (1 references)
 pkts bytes target     prot opt in     out     source               destination         
 272K   32M IN_public  all  --  eno4   *       0.0.0.0/0            0.0.0.0/0           [goto] 
42964 2736K IN_internal  all  --  eno1   *       0.0.0.0/0            0.0.0.0/0           [goto] 
    0     0 IN_public  all  --  +      *       0.0.0.0/0            0.0.0.0/0           [goto] 

Chain INPUT_ZONES_SOURCE (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 IN_drop    all  --  *      *       3.3.3.0/24       0.0.0.0/0           
    0     0 IN_drop    all  --  *      *       3.3.3.0/24       0.0.0.0/0           

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

Chain IN_drop (2 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 IN_drop_log  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 IN_drop_deny  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 IN_drop_allow  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           

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

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

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

Chain IN_internal (1 references)
 pkts bytes target     prot opt in     out     source               destination         
42964 2736K IN_internal_log  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
42964 2736K IN_internal_deny  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
42964 2736K IN_internal_allow  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    0     0 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain IN_internal_allow (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 ACCEPT     udp  --  *      *       0.0.0.0/0            224.0.0.251          udp dpt:5353 ctstate NEW
  201 15678 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:137 ctstate NEW
  627  144K ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:138 ctstate NEW
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:22 ctstate NEW
  969 50388 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:80 ctstate NEW
39727 2400K ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:60024 ctstate NEW
    7  4458 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:5080 ctstate NEW
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:8080 ctstate NEW
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:5060 ctstate NEW
 1252 90788 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:161 ctstate NEW
    0     0 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:5080 ctstate NEW
    0     0 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:5060 ctstate NEW
  140 28000 ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpts:16384:32768 ctstate NEW

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

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

Chain IN_public (2 references)
 pkts bytes target     prot opt in     out     source               destination         
 272K   32M IN_public_log  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
 272K   32M IN_public_deny  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
 272K   32M IN_public_allow  all  --  *      *       0.0.0.0/0            0.0.0.0/0           
    5   196 ACCEPT     icmp --  *      *       0.0.0.0/0            0.0.0.0/0           

Chain IN_public_allow (1 references)
 pkts bytes target     prot opt in     out     source               destination         
 1184 70012 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:22 ctstate NEW
  388  271K ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpt:5060 ctstate NEW
 268K   31M ACCEPT     udp  --  *      *       0.0.0.0/0            0.0.0.0/0            udp dpts:16384:32768 ctstate NEW

Chain IN_public_deny (1 references)
 pkts bytes target     prot opt in     out     source               destination         
    0     0 REJECT     all  --  *      *       3.3.3.0/24       0.0.0.0/0            reject-with icmp-port-unreachable
    0     0 REJECT     all  --  *      *       3.3.3.0/24       0.0.0.0/0            reject-with icmp-port-unreachable

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

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

アップデート 次のラダー ダイアグラム (sngrep) では、オプション Ping (5060) がアプリケーションによって応答されているため、ファイアウォール ルールは影響していないことがわかります。

ここに画像の説明を入力してください

アップデート2 エラーが再度発生し、フィルター ルールを再ロードすると、IP がドロップ リストに適用されなくなりました。インターフェイスにトラフィック負荷がある場合に問題が発生することがわかりました。サーバーをシャットダウンして再起動すると、ルールが適用されます。ただし、サーバーに負荷がある場合にもドロップ ルールを適用する方法が必要です。

答え1

私も同じ/類似の問題を抱えていました。何時間もトラブルシューティングを行った結果、次のような結果が得られました。

Iptables ルール チェーンの順序 (「パブリック」ゾーンの場合) は次のとおりです。

IN_public_log 
IN_public_deny
IN_public_allow

つまり、「拒否」ルールは「許可」ルールの前に処理されるので、ルールが一致する順序を理解する上でこれは重要です。この順序を変更できるかどうかはわかりません。

同じ問題に遭遇しました。 を発行してもfirewalld-cmd --reloadSIP パケットがドロップされるか受け入れられるかには影響しないようですが、再起動すると解決しました。

しかし、コマンドを見つけましたfirewalld-cmd --complete-reload。これはよりうまく機能しているようです。ただし、これにより既存のセッションがすべて削除されると思います。ただし、少なくとも、firewalld ルールを変更でき、それを完全に/適切に適用するために再起動する必要はありません。

また、sngrep は SIP メッセージがブロックされているにもかかわらず、そのメッセージをキャプチャして表示できるようですが、メッセージ数は 1 と表示され、応答メッセージはありません (実際にはブロックされているため)。

アップデート:sngrep (0.1.0以降)はlibpcapを使用していると理解しています - 参照https://github.com/irontec/sngrep/wikiこの投稿によると、libpcap は (受信) パケットを 'ファイアウォール' で処理される前に処理します。この場合の 'ファイアウォール' は、firewalld も意味すると思います。tcpdump は iptables によってドロップされているパケットを認識しますか?

注: CentOS 7 には、firewalld バージョン 0.4.4.4 が付属しているようです。最新版は 0.6.0 ですが、まだアップグレード方法がわかりません。新しいバージョンで上記の問題が解決/修正されることを期待しています。

答え2

ルールを機能させようとしながら、2 つの異なる方法でブロック ルールを作成します。最初の方法は、次の方法で IP をドロップ ゾーンに配置するというものでした。

firewall-cmd --permanent --zone=drop --add-source=3.3.3.0/24

リロード コマンドを忘れたため、ルールは適用されませんでした。次に、ファイアウォールにこのエントリを作成します。

firewall-cmd --permanent --zone=public --add-rich-rule='rule family=ipv4 source address=3.3.3.0/24 reject'

また、ファイアウォールの両方のエントリでルールを機能させることができません。3.3.3.0/24 ネットワークに関連するすべてのエントリをファイアウォールから削除し、ドロップ ゾーンでルールを再作成すると、正常に機能します。

答え3

基本的なことが抜けています。インターフェースがあり、インターフェースはゾーン(デフォルトではパブリック)に属します。そのゾーンのルールは、それに属するすべてのインターフェースに実装されます。2つのインターフェースがあります。えの1(ゾーン内内部) そしてen4(ゾーン内公共)。Nasir Riley が示唆したように、目的のインターフェースが属するゾーンにルールを実装する必要があります。ゾーンで何かを実行しようとしています。落とす「しかし、そのゾーンにはインターフェースがありません。Red Hatのドキュメントから落とすゾーン:

「着信ネットワーク パケットはすべてドロップされ、応答はありません。発信ネットワーク接続のみが可能です。」

したがって、このゾーンに希望のインターフェースを配置できますが、まず追加したルールを削除します。そして徹底的にRHEL 7 セキュリティ ガイド、firewalld に関する情報はたくさんあります。

関連情報