WordPressを日本IPのみ公開する方法|firewalld + ipset(Googlebot対応)

水冷パソコンの水温 Security

本記事では、WordPressサイトを日本国内からのアクセスのみに制限する方法を解説します。

さらに、検索エンジンに影響が出ないように
👉 Googlebotを別管理で許可する構成を採用します。


■ なぜ日本IP制限するのか

WordPressは世界中から攻撃されます:

・ログイン総当たり攻撃
・スキャン
・脆弱性攻撃


👉 日本IPのみに制限すると

攻撃の大半を遮断できます


■ 注意(最重要)

・SSHポートは必ず許可
・別セッションで確認しながら作業
・Googlebotを許可しないとSEOに影響


■ 全体構成

jp(日本IP) → 許可
googlebot → 許可
その他 → 拒否

■ ① ipset作成

sudo firewall-cmd --permanent --new-ipset=jp --type=hash:net
sudo firewall-cmd --permanent --new-ipset=googlebot --type=hash:net

■ ② Googlebot IP登録(重要)

sudo firewall-cmd --permanent --ipset=googlebot --add-entry=66.249.0.0/16
sudo firewall-cmd --permanent --ipset=googlebot --add-entry=64.233.160.0/19
sudo firewall-cmd --permanent --ipset=googlebot --add-entry=72.14.192.0/18
sudo firewall-cmd --permanent --ipset=googlebot --add-entry=74.125.0.0/16

👉 検索エンジンアクセスを維持


■ ③ 日本IP登録(初回)

curl -O https://ftp.apnic.net/apnic/stats/apnic/delegated-apnic-latest

grep '|JP|' delegated-apnic-latest | grep ipv4 | \
awk -F '|' '{print $4"/"32-log($5)/log(2)}' > jp.txt

while read line; do
  sudo firewall-cmd --permanent --ipset=jp --add-entry=$line
done < jp.txt

■ ④ 80 / 443 を制限

sudo firewall-cmd --permanent \
--add-rich-rule='rule family="ipv4" source ipset="jp" port port="80" protocol="tcp" accept'

sudo firewall-cmd --permanent \
--add-rich-rule='rule family="ipv4" source ipset="jp" port port="443" protocol="tcp" accept'

■ ⑤ Googlebot許可

sudo firewall-cmd --permanent \
--add-rich-rule='rule family="ipv4" source ipset="googlebot" port port="80" protocol="tcp" accept'

sudo firewall-cmd --permanent \
--add-rich-rule='rule family="ipv4" source ipset="googlebot" port port="443" protocol="tcp" accept'

■ ⑥ 設定反映

sudo firewall-cmd --reload

■ ⑦ 確認

sudo firewall-cmd --list-rich-rules

👉 jp と googlebot 両方が出ればOK


■ 動作確認(重要)

■ 国内回線

👉 表示される → OK


■ 海外(VPN)

👉 接続不可 → OK


■ Googlebot

👉 クロールされる → OK


■ よくあるトラブル


● サイトが見れない

→ 自分のIPがjpに含まれていない


● Googleにインデックスされない

→ googlebot未許可


● WordPress更新できない

→ 外部API制限


■ 運用ポイント(重要)

・日本IPは定期更新(cron)
・googlebotは別管理
・fail2banと併用


■ セキュリティ構成(完成形)

jp ipset → allow
googlebot → allow
blacklist → drop
fail2ban → 自動BAN

👉 ほぼ完全防御


■ 本環境

・Raspberry Pi
・Ubuntu Server
・Apache + WordPress
・firewalld + ipset + fail2ban


■ 次の記事

👉 ipset自動更新(cron)
👉 セキュリティ強化

コメント

タイトルとURLをコピーしました