Firewall Rule Generator
iptables、UFW、macOS pf、Windows Defender Firewallのファイアウォール規則を生成します。
一般的なポート
このツールについて
ファイアウォールはあらゆるネットワークシステムの最初の防線であり、コンピュータの内外を行き来するネットワークトラフィックを制御します。このツールは、Linux(iptables、UFW、nftables)、macOS(pf)、Windows Defenderなど、複数のプラットフォームでファイアウォールを設定するための正しいコマンド構文を生成するのに役立ちます。各プラットフォームの複雑な構文を覚える代わりに、目的—ポートを許可する、IPをブロックする、特定のサブネットからSSHを許可する—を指定すれば、システムに合わせたすぐに実行できるコマンドが生成されます。
システム管理者、サーバー設定の開発者、セキュリティ意識の高いユーザーは、このジェネレータを使ってルールを素早く作成し、試行錯誤を避けています。VPSの堅牢化、ホームラボの保護、ステージング環境のロックダウンなど、ルール構文が実行前に正確であることを保証します。各プラットフォームは異なるコマンド形式とフラグ規則を使用するため、このツールはドキュメント間のコンテキスト切り替えの手間を排除します。
よくある質問
コード実装
#!/usr/bin/env python3
"""Firewall rule generator — outputs iptables and UFW commands."""
def iptables_allow(port: int, protocol: str = "tcp", source: str = None) -> str:
src = f"-s {source} " if source else ""
return f"sudo iptables -A INPUT {src}-p {protocol} --dport {port} -j ACCEPT"
def iptables_block(port: int = None, source: str = None, protocol: str = "tcp") -> str:
parts = ["sudo iptables -I INPUT"]
if source:
parts.append(f"-s {source}")
if port:
parts.extend([f"-p {protocol}", f"--dport {port}"])
parts.append("-j DROP")
return " ".join(parts)
def ufw_allow(port: int, protocol: str = "tcp", source: str = None) -> str:
if source:
return f"sudo ufw allow from {source} to any port {port} proto {protocol}"
return f"sudo ufw allow {port}/{protocol}"
def ufw_deny(port: int = None, source: str = None) -> str:
if source and not port:
return f"sudo ufw deny from {source}"
if port:
return f"sudo ufw deny {port}/tcp"
return "sudo ufw deny from any"
# Examples
print("=== Allow SSH from specific IP ===")
print(iptables_allow(22, "tcp", "192.168.1.0/24"))
print(ufw_allow(22, "tcp", "192.168.1.0/24"))
print("\n=== Allow HTTP and HTTPS ===")
for port in [80, 443]:
print(iptables_allow(port, "tcp"))
print(ufw_allow(port, "tcp"))
print("\n=== Block IP ===")
print(iptables_block(source="10.0.0.5"))
print(ufw_deny(source="10.0.0.5"))
print("\n=== Save iptables rules (Ubuntu/Debian) ===")
print("sudo netfilter-persistent save")Comments & Feedback
Comments are powered by Giscus. Sign in with GitHub to leave a comment.