nftables Firewall Ruleset Review & Rewrite Prompt
Audit a messy iptables/nftables ruleset for gaps, shadowed rules, and default-allow leaks, then produce a clean, default-deny nftables rewrite with stateful tracking and logging.
- Target user
- Linux/infra engineers consolidating host firewall rules
- Difficulty
- Advanced
- Tools
- Claude, ChatGPT
The prompt
You are a senior Linux network security engineer who has migrated dozens of legacy iptables installations to clean, auditable nftables rulesets. You work defensively only — your goal is to reduce attack surface, never to find ways through someone else's firewall. I will provide: - The current ruleset (`iptables-save`, `nft list ruleset`, or a firewalld zone export) - The host's role (web server, DB, bastion, k8s node, etc.) and which ports must be reachable, by whom - Interface layout (public NIC, private/VPN NIC, loopback, container bridges) - Any management/monitoring sources that must always retain access - Known pain points (rules nobody understands, accidental lockouts, drift) Your job: 1. **Inventory & classify** every existing rule: purpose, chain, match criteria, and whether it is still needed. Flag rules that are dead, duplicated, shadowed by an earlier rule, or overly broad (e.g. `0.0.0.0/0` where a CIDR would do). 2. **Find the dangerous defaults** — default-ACCEPT policies on INPUT/FORWARD, missing established/related conntrack rules, IPv6 left wide open while IPv4 is locked down, and any rule ordering that lets traffic slip past intended drops. 3. **Rewrite as nftables**, default-deny: a single `inet` table covering v4+v6, named sets for allowed source CIDRs and service ports, a base `input` chain with `ct state established,related accept`, explicit per-service accepts, loopback accept, and a final `drop`. 4. **Logging & observability** — add rate-limited `log` rules before drops with a consistent prefix so denied traffic is greppable; note what to forward to your SIEM. 5. **Anti-lockout safety** — show the exact apply sequence (load into a temp table, test the management path, then commit) and a rollback plan so a bad rule never strands you. 6. **Persistence & idempotency** — how to install the ruleset via `/etc/nftables.conf` + systemd, and a CI check that diffs intended vs running rules. Output as: (a) annotated findings table with severity, (b) the complete rewritten `nftables.conf`, (c) the safe apply + rollback runbook, (d) the drift-detection check. Anti-patterns to call out: append-only rule sprawl, `ACCEPT` policies "temporarily", commenting nothing, and IPv6 blind spots.
Run this prompt with AI
Test it, get an AI-improved version, or compare models — live in the Prompt Workspace. No copy-paste.
Related prompts
-
Firewall & Network Egress Hardening Review Prompt
Audit and tighten host and cloud firewall rules — nftables/iptables, security groups, NACLs — toward default-deny ingress and controlled egress, eliminating overly broad 0.0.0.0/0 exposure.
-
GraphQL API Security Hardening Review Prompt
Review a GraphQL API for the abuse vectors unique to the query model — unbounded depth, introspection exposure, batching amplification, and field-level authorization gaps — and get a hardened schema and gateway config.
-
SAML SSO Assertion Security Review Prompt
Review a SAML single sign-on integration for the assertion-handling flaws that cause authentication bypass — signature validation gaps, XML canonicalization tricks, audience/recipient scoping, and replay — and get a hardened SP configuration.
-
Inbound Webhook HMAC Signature Verification Review Prompt
Review how your service authenticates inbound webhooks (Stripe, GitHub, Slack, custom senders) so forged, replayed, or tampered payloads are rejected before they trigger business logic.
More DevOps Security & Hardening prompts & error guides
Browse every DevOps Security & Hardening prompt and troubleshooting guide in one place.
Reading prompts? Get all 500 in one free PDF
500 battle-tested, copy-paste AI prompts engineered by a senior systems engineer — every one with fill-in placeholders and safety/back-out notes. Drop your email and it's yours.
- 500 prompts: Linux · Kubernetes · Terraform · OpenStack · GitLab · Docker · Monitoring · Incident Response
- Instant PDF download — yours free, forever
- Plus one practical AI-workflow email a week (no spam)
Single opt-in · unsubscribe anytime · no spam.