linux_iptables_rule_generator
Generate iptables and nftables firewall scripts from a structured rule description. Validates inputs and outputs rule text with explanations and warnings.
Instructions
Iptables And Nftables Firewall Rule Generator. Generate iptables-restore (rules.v4) and nftables (nft.conf) firewall scripts from a structured firewall description: default INPUT/FORWARD/OUTPUT chain policies, an ordered rule list (protocol, source/destination IP plus CIDR, ports, interface, action), NAT and port forwarding (DNAT/SNAT/MASQUERADE), and the common conveniences (allow loopback, allow established/related, rate-limited log-drops). Use this to author Linux netfilter rulesets; use linux_ssh_config_generator instead for ssh_config and sshd_config. It only emits rule TEXT and never runs iptables, touches no network, and reads no database: read-only, non-destructive, and rate-limited (30 requests/minute for anonymous callers). Validates IPs, CIDR suffixes, and port specs, and emits lockout warnings (such as a DROP policy without an SSH allow rule). Set operation to presets to list the 9 ready-made templates. Returns both scripts plus per-rule explanations, warnings, and target file paths.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| operation | No | generate builds firewall scripts from the input fields below; presets ignores all other fields and returns the 9 built-in templates. | generate |
| defaults | No | Default chain policies applied when generating (defaults: input ACCEPT, forward DROP, output ACCEPT). | |
| rules | No | Ordered firewall rules. Each rule maps to one iptables -A line (and an nftables equivalent). Invalid rows are silently skipped. | |
| allowEstablished | No | Prepend an INPUT rule accepting ESTABLISHED and RELATED connections via conntrack. | |
| allowLoopback | No | Prepend an INPUT rule accepting all traffic on the loopback interface. | |
| logDrops | No | Append a rate-limited LOG rule on INPUT before the default policy applies. |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| success | No | Whether the request succeeded. | |
| operation | No | The operation performed (generate or presets). | |
| result | No | For generate: the produced scripts. For presets: a presets array of named templates. |