Skip to content

📋 Firewall Cheat Sheet

UFW vs firewalld Command Comparison

OperationUFWfirewalld
Enable/Disableufw enable/disablesystemctl start/stop firewalld
View statusufw statusfirewall-cmd --state
Allow portufw allow 80/tcpfirewall-cmd --add-port=80/tcp
Deny portufw deny 3306/tcpfirewall-cmd --add-port=3306/tcp --zone=drop
Allow serviceufw allow sshfirewall-cmd --add-service=ssh
Rate limitufw limit 22/tcp--add-rich-rule='...limit value="5/m"...'
View rulesufw status numberedfirewall-cmd --list-all
Delete ruleufw delete 3firewall-cmd --remove-port=80/tcp
PersistentAutomatic (ufw rules are persistent by default)--permanent + --reload
Loggingufw logging mediumfirewall-cmd --set-log-denied=all

Firewall Selection Guide

ScenarioRecommendationReason
Ubuntu DesktopUFWInstalled by default, easy to use
Ubuntu ServerUFW or nftablesUFW is sufficient; use nftables for complex scenarios
CentOS/RHEL 7firewalldInstalled by default, supports dynamic rules
CentOS/RHEL 8+nftablesfirewalld backend has switched to nftables
Docker Hostnftables + DOCKER-USERDocker bypasses UFW/firewalld
High concurrency/large scalenftablesSet matching O(1), best performance

💡 Tip: 💡 Ultimate advice: Regardless of which tool you use, understanding the underlying packet filtering principles (iptables chains/tables/matches/targets) is the core. Tools change, principles don't. Once you master iptables, switching to any other tool only requires learning the syntax.