GNU/Linux >> Linux の 問題 >  >> Linux

ホストのブラックリストとiptablesをブロックする

イントロ:
サーバーへのアクセスをブロックすることにした特定のホストからの攻撃が発生しました。これは、IP/範囲のリストを含むファイルに基づいて完全なiptablesCHAINを削除して再ロードするスクリプトを使用して行った方法です。

手順:
スクリプトと同じディレクトリに、1行に1つのIP/範囲を持つblacklist.txtというファイルを作成します。
例:
14.141.107.206
23.180.0.0/14
37.59.34.120
46.140.157.157
46.218.35.59
47.74.0.40
51.15.56.170
59.62.0.0/15
59.63.188.3
61.177.172.60

起動時に実行するスクリプト
#!/bin/bash
# Tiny firewall protecting rpcbind (port 111)
scriptdir=$(dirname $(readlink -f $0))
blacklist="$scriptdir/blacklist.txt"
# Load the blacklists
HOSTS="$(cat $blacklist | egrep -v '^$|#')"
# Delete the existing custom chain
/sbin/iptables --flush BLACKLIST
/sbin/iptables -X BLACKLIST
/sbin/iptables -t filter -D INPUT -j BLACKLIST
# Create the BLACKLIST Chain and jump
/sbin/iptables -N BLACKLIST
/sbin/iptables -t filter -I INPUT -j BLACKLIST
# Fill-in the BLACKLIST Chain with rejected hosts list
for host in $HOSTS ; do
/sbin/iptables -A BLACKLIST -s $host -p tcp -j DROP
done
# Return from Blacklist
/sbin/iptables -A BLACKLIST -j RETURN
#eof

注: iptablesは次のエラーで文句を言います。心配しないでください、それでも適切な仕事をします。
iptables: Too many links.
iptables: Chain already exists.


Linux
  1. IPSetとIPTablesを使用して個々の国からのすべてのトラフィックをブロックする

  2. Iptablesと透過プロキシ?

  3. 複数のホストにSSHで接続し、コマンドを実行しますか?

  1. GeoIPとiptablesがある国からのIP範囲をブロックする

  2. Fail2Ban Howto:Fail2ban と IPTables を使用して IP アドレスをブロックする

  3. IPTables と DHCP に関する質問ですか?

  1. / etc / hostsを補完するユーザー固有のHostsファイルを作成しますか?

  2. cPanelとMySQLアクセスホスト

  3. iptables - ブリッジ アンド フォワード チェーン