DevTools Logo

Firewall Rule Builder (UFW & iptables)

Firewall Rule Builder (UFW & iptables)

Compose allow/deny rules once and get ufw commands, iptables rulesets, first-match simulation and lockout warnings.

Runs in your browser
Try a preset

Rules and policies

0 rule(s) · 0 error(s)

No rules yet. Add one or choose a preset above.

Generated rules

Add a rule to generate commands

Choose a preset to see both dialects at once.

Safety advisories

  • Warning: INPUT policy is restrictive and no management-port (22/3389) allow rule exists. Keep an active console session before applying.

Details

Describe a rule once — action, direction, interface, protocol, ports, source, destination and comment — and the builder emits both ufw commands and ordered iptables rules from the same model. A first-match simulator walks your rules in order for a test source, port and protocol, so you can see which rule wins before applying anything. Default policies are included in the output along with an SSH lockout guard, shadow-rule detection and a console-session warning. Presets cover a web server, hardened SSH and a database subnet. Generated scripts are inert text: this tool never executes commands or connects to your machine.

More examples

SSH from the VPN only

allow · in · tcp · 22 · source 10.0.0.0/8 · comment 'SSH from VPN'

→ ufw allow in tcp from 10.0.0.0/8 port 22 comment 'SSH from VPN'
→ iptables -A INPUT -p tcp -m tcp --dport 22 -s 10.0.0.0/8 -j ACCEPT

One rule produces both dialects with the source restriction intact.

Web server defaults

INPUT DROP · OUTPUT ACCEPT · FORWARD DROP
allow 22 from VPN · allow 80,443 from any

→ policy lines first, rules in order, console-session warning

The generated ruleset includes the policy context admins often forget.

First-match simulation

rule 1: deny tcp 22 from 10.0.0.0/8
rule 2: allow tcp 22 from any

test src 10.1.2.3:22 → DROP

iptables stops at the first match, so the later allow never applies.

Chunked multiport

ports 3000-3019 → two iptables lines of at most 15 ports each

The multiport module has a 15-port limit; the compiler splits long lists automatically.

    Examples

    VPN-only SSH

    Input
    allow in tcp 22 from 10.0.0.0/8
    Output
    iptables -A INPUT -p tcp -m tcp --dport 22 -s 10.0.0.0/8 -j ACCEPT

    One model produces matching ufw and iptables commands with the source restriction.

    Shadowed deny

    Input
    1. allow tcp 80 · 2. deny tcp 80
    Output
    Rule 2 is shadowed by rule 1

    The simulator and advisory both show that the deny can never apply.

    Invalid CIDR

    Input
    source 10.0.0.0/33
    Output
    Invalid source CIDR — fix before generating

    Validation runs before either compiler emits commands.

    About this tool

    Firewall Rule Builder turns a small rule table into two dialects: ufw commands for humans and ordered iptables rules for scripts. Each row carries action, direction, interface, protocol, ports, source, destination and a comment; both compilers derive from that single model so they cannot drift apart.

    The output includes default policies, an optional conntrack starter, a first-match simulator and safety advisories for SSH lockouts, unrestricted management access and shadowed rules. Presets for a web server, hardened SSH and a database subnet are editable rows rather than opaque blobs.

    Nothing is executed. Generated scripts are text you review and apply yourself, ideally from an active console session. Internal CIDRs and topology stay in the browser tab.

    What this tool does not do

    • nftables and firewalld are out of scope; only ufw and iptables are generated.
    • IPv6 mode emits ip6tables commands but does not simulate IPv6 CIDR membership.
    • Conntrack starter rules are shown in output but are not part of the first-match simulation.
    • Generated text is never applied or validated against a live firewall; review before running it.

    How to use this tool

    1. Start from a preset

      Load web-server, SSH-hardened or database, or add an empty rule and fill in the fields.

    2. Set default policies

      Choose INPUT, OUTPUT and FORWARD policies; a restrictive INPUT with no management allow raises a warning.

    3. Choose a dialect

      Switch between ufw and iptables. Both show the same rules with dialect-correct flags and quoting.

    4. Test the order

      Enter a source IP, port, protocol and direction; the verdict shows the first matching rule or the chain policy.

    5. Export and review

      Copy the active dialect or download a full setup script; keep a console session open when applying.

    Use cases

    VPS hardening

    Allow SSH from a VPN subnet, open HTTP/HTTPS and close everything else with policy context.

    Bootstrap scripts

    Export an ordered iptables script plus ufw equivalents for a new machine.

    Learning netfilter

    Experiment with first-match semantics and see why rule order matters.

    Rule fields

    FieldExample
    actionallow / deny / reject
    directionin / out
    protocoltcp / udp / any / icmp
    ports80,443 or 8000-8010
    source / destination10.0.0.0/8
    commentSSH from VPN

    iptables evaluates top to bottom, so reordering rules changes the verdict.

    Common mistakes

    Mistake:Applying a DROP policy without an SSH allow rule.

    Fix:Keep an active console session and heed the lockout advisory.

    Mistake:Expecting a later deny to override an earlier broad allow.

    Fix:Reorder rules or narrow the allow; iptables stops at the first match.

    Mistake:Putting more than 15 ports in one multiport rule.

    Fix:The builder chunks long lists into multiple commands automatically.

    Mistake:Assuming ufw governs Docker-published ports.

    Fix:Docker inserts its own chains; manage those ports with iptables/nftables.

    Frequently asked questions

    What is the difference between ufw and iptables?

    ufw is a friendly front end that writes netfilter rules for you; iptables talks to the kernel chains directly and gives finer control. This tool emits both from one rule model so the commands stay in sync.

    Which rule matches first?

    iptables walks the chain from top to bottom and stops at the first match. The simulator highlights that rule and marks later rules as unused; reordering rows changes the verdict immediately.

    How do I avoid locking myself out of SSH?

    Keep an active console session, add an allow rule for port 22 from your admin subnet before broad denies, and read the in-output warning. The builder flags a restrictive INPUT policy with no management allow and flags management access from anywhere.

    How do default policies work?

    Policies decide the fate of packets that match no rule. A DROP INPUT policy is a good hardening baseline once required services are explicitly allowed; OUTPUT is usually ACCEPT and FORWARD is usually DROP on a host.

    Should I use nftables instead?

    On modern distributions nftables is the successor to iptables, but iptables remains widely deployed and ufw still uses it underneath. This tool deliberately covers those two dialects; port the emitted logic to nft syntax if your host uses it.

    Does this tool execute the generated commands?

    No. Everything is inert text computed in your browser. Your network setup and internal CIDRs never leave the tab, and nothing connects to or changes your machine.

    References & standards