Linux

UFW Rule Generator

Generate UFW rules for Ubuntu/Debian: allow or rate-limit a port, restrict to a source, with verification and deletion commands.

E.g. 443, 5060:5061. Leave empty if you are only targeting a source.

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.

actionlimit
directionin
protocoltcp
port22
source
source_port
commentSSH anti-brute-force
Load this example

Public HTTPS

Simple allow rule.

actionallow
directionin
protocoltcp
port443
source
source_port
commentHTTPS public
Load this example

Restricted administration

Access limited to a specific network.

actionallow
directionin
protocoltcp
port8443
source203.0.113.0/24
source_port
commentAdmin bureaux
Load this example

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>.