Linuxはiptablesを使用して特定のドメイン名をブロックします



Linux Uses Iptables Block Certain Domain Names



通常、iptablesには文字列モジュールが付属しています。このモジュールの機能は、文字列を照合し、汎用ドメイン名のURLを照合してからパケットを破棄することで、汎ドメイン名をブロックする機能を実現します。たとえば、YouTube.comへのSSアクセスを制限できます

The following rule is to block all first-level, second-level, third-level domain names based on youtube.com. iptables -A OUTPUT -m string --string 'youtube.com' --algo bm --to 65535 -j DROP # Add blocking rules iptables -D OUTPUT -m string --string 'youtube.com' --algo bm --to 65535 -j DROP # Delete the blocking rule, what is the code added above, then delete the code is to change -A to -D

説明:



-A # Add iptables rules -D # Delete the iptables rule (change the added rule by changing -A to -D in the code when adding the firewall rule) -m string # specify module --string 'youtube.com' # Specify the string to be matched (domain name, keyword, etc.) --algo bm # Specify matching string pattern/algorithm (and a more complicated algorithm: kmp) --to 65535 # Specify the port, which represents all ports (1-65535) -j DROP # Refers to the way to match the packet after processing, here is to drop the packet.

このモジュールの役割は文字列を照合することです。この文字列はURL、プレーンテキスト、ファイルサフィックスにすることができます(後者の2つ、ターゲットサイトでGZIPクラス圧縮アルゴリズムが有効になっている場合、結局、一致をフィルタリングできません。 、圧縮されています)

例:.zip、.zipを含むデータベースは破棄されるため、.zipタイプのファイルをダウンロードすることはできません。



他の役割はゆっくりと研究することができます。

この記事はから複製されます https://doub.io/wlzy-25/

転載:https://www.jianshu.com/p/b1374ea46eb7