UFW Rule Generator
Generate UFW rules for Ubuntu/Debian: allow or rate-limit a port, restrict to a source, with verification and deletion commands.
How it works
UFW simplifies iptables on Ubuntu/Debian. An allow rule permits, deny blocks silently, reject refuses with an ICMP reply, and limit adds brute-force protection on a port (ideal for SSH).
Order of evaluation: UFW evaluates rules in order and then applies its default policy (deny incoming is recommended). Always test your SSH rules before enabling the firewall, and use ufw status numbered to manage rules.
Examples
Secure SSH
Limit rule on port 22.
| action | limit |
| direction | in |
| protocol | tcp |
| port | 22 |
| source | |
| source_port | |
| comment | SSH anti-brute-force |
Public HTTPS
Simple allow rule.
| action | allow |
| direction | in |
| protocol | tcp |
| port | 443 |
| source | |
| source_port | |
| comment | HTTPS public |
Restricted administration
Access limited to a specific network.
| action | allow |
| direction | in |
| protocol | tcp |
| port | 8443 |
| source | 203.0.113.0/24 |
| source_port | |
| comment | Admin bureaux |
Frequently asked questions
UFW or nftables directly?
UFW is a simple front end for nftables: perfect for a standalone server. Complex environments will prefer nftables directly.
How do I avoid locking myself out of SSH?
Allow/limit SSH first, check with ufw status, then enable. Keep a backup console (KVM) accessible.
How do you delete a rule?
ufw status numbered then ufw delete <number>.