Firewall Rule Builder

iptables · ip6tables · UFW · firewalld · new rules go on top · .sh with automatic undo

✅ ALLOW
MYSYSAD.COM
The safeguard keeps this port out of blocks. Change it if SSH listens somewhere other than 22. Use a port from 1 to 65535
Rule Configuration
Use a port from 1 to 65535, or a range like 8080:8090
Invalid — e.g. 192.168.1.0/24 or 2001:db8::/32
Invalid — e.g. 10.0.0.0/8
Invalid — an interface name like eth0, ens3 or wg+ (up to 15 letters, digits, . _ - +)
⚡
New rules go at the top, in the order of your chain Firewalls check rules from the top and stop at the first match, so a rule added at the end can do nothing. Each new rule goes above the ones you already have: iptables -I with numbered places, ufw prepend, and for a chain in firewalld, priorities in order.

Blocking ICMP blocks ping only, since the other ICMP messages keep connections (and IPv6) working. When you allow traffic, -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT is added too, unless you already have it, so replies keep working.

Quick Fill:
Generated Commands
iptablesIPv4
0
Configure a rule and click Generate →
ip6tablesIPv6
0
Enable dual-stack toggle above →
ufwUbuntu / Debian
0
Configure a rule and click Generate →
firewalldRHEL / Fedora / AlmaLinux
0
Configure a rule and click Generate →

Rule Chain

0 rules
No rules in chain yet — configure a rule and click “Add to Chain”. Rules are checked from the top.
⚠️
⚠ Important — these commands change the firewall at once A rule that blocks the way you connect can lock you out of a remote server. Keep the SSH Safeguard on, and prefer the .sh script: it saves your current rules first and puts them back unless you type yes within 60 seconds. If you paste commands by hand, save first: iptables-save > /root/rules.v4.bak. Test rules on a lab machine before production. MYSYSAD bears no liability for service outages, data loss, or security incidents caused by misconfigured firewall rules.
Share MySysAd

⚠️ IMPORTANT: Tools are provided "AS IS" for educational purposes only.

By using this site you agree to our Terms of Service. © MYSYSAD — All rules generated locally · Zero uploads.

Firewall rules that won’t lock you out

Describe a rule (action, protocol, port, addresses, interface and direction), or a chain of them, and get it for iptables and ip6tables, UFW and firewalld, each in that firewall’s own syntax. Firewalls check rules from the top and stop at the first match, so new rules go at the top in the order you list them. When a block would also stop SSH, it leaves SSH’s port out. The downloaded script saves your current rules and puts them back unless you type yes within 60 seconds, so a mistake can’t lock you out.

Common questions

Why doesn’t my new iptables rule work?

Rules are checked from the top and the first match wins. A rule added with -A goes at the end, after rules that already accept or reject the traffic; on RHEL-style servers the list ends with a rule that rejects everything, so anything appended after it never runs. Insert it instead, iptables -I INPUT 1 …, and check the order with iptables -L --line-numbers -n.

How do I avoid locking myself out when changing firewall rules over SSH?

Save the current rules first (iptables-save > /root/rules.v4), and have them put back automatically unless you confirm: iptables-apply on Debian and Ubuntu does this, and so does this tool’s .sh script. Keep SSH out of any broad block, and test from a second SSH session before you close the first.

Why does ufw deny not block an address?

UFW checks its rules in order too, and ufw deny adds the rule at the end, after your allow rules. Use ufw prepend deny from 203.0.113.7 (or ufw insert 1) so the block comes first, then check with ufw status numbered.

Why didn’t my firewall-cmd rule do anything?

Changes made with --permanent only start after firewall-cmd --reload. Also check that the rule went into the zone your interface is actually in: firewall-cmd --get-active-zones.

Do I need separate rules for IPv6?

Yes, if you use iptables: iptables only filters IPv4 and ip6tables handles IPv6, so a server with an IPv6 address can be wide open while the IPv4 rules look perfect. UFW and firewalld cover both. Don’t block all ICMPv6: IPv6 needs it for neighbour discovery and “packet too big”, so block ping (--icmpv6-type echo-request) instead.

How do I make iptables rules survive a reboot?

iptables rules live in memory. On Debian and Ubuntu, install iptables-persistent and run sudo netfilter-persistent save. On RHEL-based systems, firewalld is the default; if you use plain iptables there, install iptables-services and run sudo service iptables save.

Related tools: Port Reference · SSH Doctor · NetBuilder Pro · All tools A–Z