1. Home
  2. Developer tools
  3. Firewall Rule Generator

Firewall Rule Generator

Lock down a new VPS or server quickly, with the same rules written for whichever firewall the distribution uses.

Free, no sign-up. Runs in your browser: nothing is uploaded.

How to use Firewall Rule Generator

  1. Add rules: allow, deny or rate-limit, port, protocol and source.
  2. Pick ufw, iptables or nftables and the default policy.
  3. Copy the commands and test from a second session.

Features

  • ufw, iptables and nftables output from one rule list
  • Port lists and ranges (80,443 or 8000-8100)
  • Source IPs and CIDR ranges
  • Rate-limited SSH against brute-force attempts
  • Lock-out warning when SSH is not allowed

Supported formats

Input

  • Form input

You get

  • SH
  • CONF

Private by design

Everything you enter is processed by your browser on this device. Nothing is sent to openWorkstand or anyone else, so the Firewall Rule Generator is safe for private and work data. After you have used it once while online, it also works without an internet connection. How local processing works

Good to know

  • iptables output covers IPv4; repeat the rules with ip6tables for IPv6.
  • Rules are not applied for you; test them from a second session.

Guide

Writing Linux firewall rules with ufw, iptables or nftables

A new server on the internet receives login attempts within minutes. A host firewall that only accepts the ports you actually serve is the simplest protection, but the three common front ends, ufw, iptables and nftables, each have their own syntax. This generator keeps one list of rules and writes it for whichever firewall your system uses.

Policies and order

A firewall decides what to do with traffic in two steps. Rules are checked in order and the first match wins; traffic that matches no rule gets the default policy. The safe pattern for a server is a default of “deny incoming, allow outgoing” with explicit allow rules for the services you run, so anything you forget stays closed. Put specific deny rules above broad allow rules, or they will never be reached.

One list, three outputs

ufw, the Uncomplicated Firewall on Ubuntu, gets one readable command per rule, such as sudo ufw allow from 10.0.0.0/24 to any port 5432 proto tcp, followed by enabling it. iptables gets rules for the INPUT chain, starting with the two everyone needs: accept packets that belong to established connections and accept the loopback interface. nftables gets a complete ruleset in an inet table, which covers IPv4 and IPv6 at once, with port lists written as sets like { 80, 443 }.

Rate limiting SSH

Choosing “Rate-limit” for a port turns on brute-force protection. In ufw that is the limit action, which denies an address after six connection attempts within 30 seconds. In iptables the recent module counts new connections per source, and in nftables a limit rate expression caps new connections per minute. Legitimate users rarely notice; password-guessing bots slow to a crawl.

Sources, ports and protocols

Leave the source empty to match any address, or enter a single IP or a CIDR range such as 192.0.2.0/24 to allow only an office or private network. Ports can be single numbers, comma-separated lists or ranges like 8000-8100. “Both” writes the rule for TCP and UDP, which suits services such as DNS on port 53.

A worked example

The Sample rules rate-limit SSH, allow web traffic on 80 and 443, allow PostgreSQL only from 10.0.0.0/24 and block one address. In ufw form the output starts with sudo ufw default deny incoming and sudo ufw default allow outgoing, then sudo ufw limit from any to any port 22 proto tcp comment "SSH, rate-limited", the allow rules and sudo ufw deny from 203.0.113.7, and ends with sudo ufw enable. Switching to nftables gives a chain with policy drop; and the line tcp dport { 80, 443 } accept comment "Web".

Applying rules safely

Changing a firewall over SSH can cut your own connection. Keep the current session open, apply the rules, and test logging in from a second terminal before closing the first. The tool warns when a default-deny policy is on and no rule allows port 22. On cloud servers, a provider console or security group gives you a way back in if something goes wrong.

Things to know

Docker publishes container ports by writing its own iptables rules, which bypass ufw, so publish ports on 127.0.0.1 when they should stay private. The iptables output covers IPv4; repeat it with ip6tables or use nftables for IPv6. Cloud firewalls and security groups are a separate layer that also needs the right ports.

Checked against the current version of the Firewall Rule Generator on .

Frequently asked questions

How do I undo a ufw rule?

Run sudo ufw status numbered to list the rules with numbers, then sudo ufw delete followed by the number. You can also delete by repeating the original rule after delete, for example sudo ufw delete allow 8080/tcp.

Do my iptables rules survive a reboot?

Not by default; they live in kernel memory. Save them with iptables-save into /etc/iptables/rules.v4 and install a loader such as the iptables-persistent package on Debian and Ubuntu. nftables reads /etc/nftables.conf at boot when the nftables service is enabled.

Does Docker bypass ufw?

Yes, by default: Docker writes its own iptables rules for published ports, which are evaluated before ufw’s. Publish ports only on 127.0.0.1, or use the DOCKER-USER chain, if a container should not be reachable from outside.

Which should I use, ufw or nftables?

ufw is the simplest on Ubuntu and Debian and is a front end to the kernel firewall. nftables is the modern kernel interface that replaces iptables; write it directly when you need sets, maps or one file that covers IPv4 and IPv6.

Keep working with the result

openWorkstand also includes a free workspace with documents, spreadsheets, tasks, projects and a calendar that save to a folder on your computer.