Firewall Rule Generator
One firewall policy, written for nine firewalls — and a way back if it locks you out.
Try before you buy.
- Free preview: the warnings and notes in full, with the first lines of each rules file and of the safe-apply steps (up to 20) and the first rows of an explanation.
- Locked until you unlock it: download and copy.
- Unlock: Pro pass, ₹179 for 30 days or ₹79 for 1 week, a one-time payment that never renews. Unlock: Pro pass, $5.99 for 30 days or $2.99 for 1 week, a one-time payment that never renews.
Ways to unlock shows how to get the full result.
Printing this result is locked in the free preview.
Rules
Apply safely, with an automatic rollback
Apply firewall rules from a second session, and keep the one you are in open until a new connection works. These steps undo the change by themselves if you are locked out.
Explain existing iptables rules
Every rule is put into words, and common mistakes are pointed out. Read on your device; nothing is sent anywhere.
| Line | Rule | What it does |
|---|
Locked in the free preview. Opens the ways to unlock this result.
Locked in the free preview. Batch runs unlock with a pass.
Locked in the free preview. Query results unlock with a pass.
About the Firewall Rule Generator
A server firewall should refuse every incoming connection except the few it is there for. Writing that by hand means remembering a different syntax for each firewall — and one wrong line can lock you out of your own server. Fill in the form once: SSH (from anywhere, or only from your own addresses, with a per-address limit on new connections), web ports and any other ports, ping, IPv6, and whether refused traffic is dropped or rejected. The generator writes the same policy for UFW, iptables (rules.v4 and rules.v6), nftables, firewalld, Windows Defender Firewall (PowerShell), pf, AWS security groups, Google Cloud firewall rules and Azure network security groups.
Every line is explained in a comment, the parts each firewall cannot express are listed under the rules, and Apply safely gives the steps that test the rules first and undo them by themselves if you lose access — iptables-apply, a timed systemd-run rollback, firewalld’s runtime configuration, a scheduled task on Windows or at for pf. Paste your current iptables-save output under Explain existing iptables rules to get every rule in plain words and the usual mistakes pointed out.
Without a pass you see a free preview: the warnings and notes in full, the first lines of each rules file and of the Apply safely steps, and the first rows of the explanation of existing rules. The full rules and steps, and copying or downloading them, unlock with a Pro pass.
How to use it
- Choose who may use SSH: anywhere, or only your office, home or VPN addresses (one per line, CIDR ranges allowed). Keep the rate limit on to slow down password guessing.
- Tick the web ports you serve, and add other services under Other ports, one per line:
5432/tcp from 10.0.0.0/8 # PostgreSQL. - Set the options: matching IPv6 rules, ping, logging, and whether refused connections are dropped or rejected.
- Pick your firewall above the rules. Read the warnings and the notes, then copy or download the rules with a pass, or after unlocking this result.
- Open Apply safely and follow its steps from a second session, keeping your current one open until a new connection works (the whole list, and copying it, with a pass).
- To check rules a server already has, paste
sudo iptables-saveinto Explain existing iptables rules.
Examples
SSH from 198.51.100.0/24 with at most 6 new connections a minute per address; HTTP and HTTPS; IPv6 on; drop refused traffic
iptables: -A INPUT -p tcp -s 198.51.100.0/24 --dport 22 -m conntrack --ctstate NEW -m hashlimit … --hashlimit-above 6/minute … -j DROP, then the same rule with -j ACCEPT; nftables: ip saddr 198.51.100.0/24 tcp dport 22 ct state new update @ssh_tcp_22_v4 { ip saddr limit rate 6/minute burst 6 packets } accept; UFW: sudo ufw limit proto tcp from 198.51.100.0/24 to any port 22Other ports: 5432/tcp from 10.0.0.0/8 # PostgreSQL
firewalld: rule family="ipv4" source address="10.0.0.0/8" port port="5432" protocol="tcp" accept · Windows: New-NetFirewallRule -DisplayName 'PostgreSQL (TCP 5432)' … -LocalPort 5432 -RemoteAddress 10.0.0.0/8
The same port without “from” makes the page warn that PostgreSQL is open to every address.
-A INPUT -p tcp -m tcp --dport 22 -m conntrack --ctstate NEW -m recent --update --seconds 60 --hitcount 4 --name SSH --rsource -j DROP
Silently drop new TCP connections to port 22 (SSH), when the source address is in the list “SSH” at least 4 times within 60 seconds.
Common uses
- Locking down a new VPS or cloud server: SSH from your own address, web ports for everyone.
- Moving a server from iptables to nftables, or from UFW to firewalld, with the same policy.
- Writing matching cloud security group rules and a host firewall for defence in depth.
- Reviewing an inherited server’s iptables rules before changing them.
- Opening a database or admin port only to the application network.
What every ruleset contains
- Default deny for incoming traffic and for routing, while outgoing traffic is allowed.
- Loopback and replies to the server’s own connections (connection tracking: ESTABLISHED, RELATED), without which DNS lookups and updates fail.
- The ICMP errors that keep connections working, and for IPv6 neighbour discovery from the local link (hop limit 255, RFC 4861) and packet-too-big — dropping all ICMPv6 breaks IPv6 (RFC 4890).
- DHCP and DHCPv6 replies, for servers that get their addresses that way, as UFW’s own rules do.
- Your services, each limited to the addresses you give, then optional rate-limited logging and, if chosen, a reject reply (TCP reset or ICMP unreachable) instead of a silent drop.
Rate limits per address
Each address may open only so many new connections a minute; replies and connections already open are not affected. iptables uses the hashlimit match, nftables a dynamic set with a limit per address (nftables wiki), pf max-src-conn-rate with an overload table that blocks the offender (pf.conf(5)). UFW’s limit is fixed: 6 connections within 30 seconds (ufw(8)). firewalld’s rule limits count every source together, so the page does not use them; Windows Firewall and the cloud firewalls have no rate limit — the notes say so, and fail2ban on the host covers it.
Applying without locking yourself out
- Work from a second session, and keep the one you are in open: connections already open are tracked as established and keep working.
- iptables:
iptables-restore --testchecks a file, and iptables-apply loads it and restores the old rules unless you confirm in time. - nftables:
nft -c -fchecks the file; a copy of the old ruleset is restored by asystemd-run --on-activetimer unless you stop it. - UFW: rules can be added while it is off; a timer runs
ufw disableunless you cancel it. - firewalld: changes without
--permanentare runtime only, so a reload restores the saved rules (firewall-cmd). - Windows:
netsh advfirewall exportsaves the policy and a scheduled task imports it back unless you delete the task. - pf:
pfctl -nfparses without loading, and anatjob loads the old file. Cloud: add the new rules first, test, then remove the old, wider ones.
Things to know per firewall
- Docker publishes container ports in the nat table, before the INPUT rules of UFW or iptables see them; filter container traffic in the DOCKER-USER chain (Docker documentation). Loading a whole iptables table or
nft flush rulesetalso removes Docker’s rules until Docker restarts. - Use one firewall manager: UFW, firewalld or your own iptables/nftables files, not several.
- AWS security groups only allow, are stateful and start with no inbound rules (AWS). Google Cloud rules hold either IPv4 or IPv6 ranges, cannot pick ICMP types, and the default network ships rules that open SSH, RDP and ping to everyone (Google Cloud). Azure NSG priorities run from 100 to 4096 and the default rules allow all traffic from inside the virtual network (Azure).
- Windows rules are created with New-NetFirewallRule in one group, so
Remove-NetFirewallRule -Grouptakes them all away again.
Limitations
- Inbound filtering for a single host: no NAT, port forwarding, routing between networks or outbound restrictions.
- The rules are generated from the documented syntax and checked against each firewall’s documentation, but your system may differ: always run the test step first.
- The explainer reads iptables (iptables-save, iptables -S and iptables commands), not nftables or other firewalls’ rules; uncommon match modules are named but not explained.
- Cloud outputs use placeholders (sg-0123456789abcdef0, NETWORK, RESOURCE_GROUP, NSG_NAME) that you replace with your own names.
Privacy
On this device: nothing is sent
Everything happens in your browser. What you enter or open here is not uploaded or stored by MySmartCoPilot.
Frequently asked questions
What do I get without a pass?
Without a pass, Firewall Rule Generator shows the warnings and notes in full, with the first lines of each rules file and of the safe-apply steps (up to 20) and the first rows of an explanation. Until you unlock it, the result can’t be downloaded or copied. A Pro, Premium or Ultimate pass, a one-time payment that never renews, unlocks the full result. The pricing page lists the passes and their prices.
Which firewall does my server use?
Ubuntu ships UFW (check with sudo ufw status); Fedora, RHEL, Rocky and AlmaLinux ship firewalld (sudo firewall-cmd --state). Both drive nftables or iptables underneath, so use their output there rather than writing those rules yourself. A minimal Debian server often has neither: use the nftables output. On a cloud server, set the provider’s security group or firewall rules too.
Drop or reject refused connections?
Dropping says nothing: a scanner has to wait for a timeout, and the server looks absent. Rejecting answers at once with a TCP reset or an ICMP unreachable message, so mistakes are easier to diagnose. Both refuse the connection equally; drop is the more common choice for servers on the internet.
Should SSH be open to everyone?
Only if you must sign in from changing addresses. Allowing just your office, home or VPN addresses stops almost all password guessing. Otherwise keep the rate limit, use keys instead of passwords, and read your server’s sign-in log (auth.log, or the Windows Security log) to see who is trying.
Do I still need these rules if the cloud firewall blocks everything?
It is good practice to have both: the cloud rules protect the server before traffic reaches it, the host firewall protects it if a cloud rule is changed or the server moves, and it can do what cloud firewalls cannot, such as rate limits per address.
Why is ICMP allowed?
Some ICMP messages are part of how networks work: “destination unreachable” and “packet too big” tell a sender to adjust, and IPv6 finds its router and neighbours with ICMPv6. Blocking all of them causes hard-to-find failures. Ping (echo request) is optional and can be switched off.