Free tools / UFW rules generator
UFW firewall rules generator
Generate ufw commands for a Linux server in the right order: default policies first, SSH next, then your services, and ufw enable last. Start from a preset or add your own ports, and limit sensitive ports to a single IP address.
Everything runs in your browser. Nothing you type is sent to a server or stored.
SSH
Presets
Custom rules
No custom rules yet.
Port ranges like 6000:6007 need tcp or udp.
# Generated at nocthost.com/tools/ufw-generator
# 1. Default policy: block incoming, allow outgoing
sudo ufw default deny incoming
sudo ufw default allow outgoing
# 2. SSH first, so enabling the firewall does not cut your session
sudo ufw limit 22/tcp comment 'SSH'
# 3. Services
sudo ufw allow 80/tcp comment 'HTTP'
sudo ufw allow 443/tcp comment 'HTTPS'
# 4. Turn it on and check
sudo ufw --force enable
sudo ufw status verbose
How to use
- Set the SSH port you actually use, and a source IP if you want SSH open only to your own address.
- Tick the presets you need and add custom rows for anything else. Database and remote desktop ports should get a source IP.
- Copy the commands and run them on the server from top to bottom.
- Check the result with sudo ufw status verbose, then open a new SSH session to confirm you can still get in.
Frequently asked questions
Why does the order of the commands matter?
ufw enable applies the default deny policy immediately. If SSH is not allowed by then, your current session can drop and new logins fail. Allowing SSH before enabling the firewall avoids that.
Does ufw protect ports published by Docker?
No. Docker writes its own iptables rules that are evaluated before the ufw rules, so a port published with -p 8080:80 is reachable from the internet even if ufw denies it. Bind containers to 127.0.0.1 and put a reverse proxy in front, or filter in the DOCKER-USER chain.
What is the difference between ufw allow and ufw limit?
limit allows the connection but blocks an address that opens 6 or more connections within 30 seconds. It suits SSH. Do not use it for web traffic, where one visitor can open many connections at once.
Can I use this on a Windows server?
No, ufw is a Linux tool. The RDP preset is for xrdp on Linux desktops. On Windows Server, restrict port 3389 in Windows Defender Firewall or in the cloud firewall of your provider.
Further reading
More free tools
- SSH hardening config generatorKey-only login, root off, AllowUsers, timeouts and modern ciphers as a drop-in or a full sshd_config.
- Cloud-init user-data generatorA #cloud-config file for first boot: sudo user, SSH key, updates, ufw, fail2ban, auto updates and swap.
- WireGuard config generatorA server wg0.conf and up to 10 client configs with browser-generated keys, NAT rules and setup commands.
- Nginx reverse proxy config generatorAn nginx server block for a local app with Let's Encrypt HTTPS, WebSocket, redirects, gzip and rate limiting.
- Systemd service file generatorA .service unit for your app with user, environment, restart policy and optional hardening, plus the enable commands.
Need a server to try it on? Deploy an Ubuntu VPS