sudo ufw status verboseWhether it's on, the default policy, and every rule.
Cheat sheet
Opening ports, blocking addresses and seeing the rules that are really there, with ufw (Debian, Ubuntu) and firewalld (Fedora, Rocky, RHEL).
Nothing you type here is sent. Nothing is saved, unless you switch on Remember. Privacy policy
Working over SSH? Allow SSH before you switch a firewall on, or you'll lock yourself out of the machine you're working on. Ubuntu and Debian usually use ufw; Fedora, Rocky and RHEL use firewalld. Both write their rules into nftables underneath.
Nothing matches that. Try fewer words, or a shorter one.
sudo ufw status verboseWhether it's on, the default policy, and every rule.
sudo ufw allow 22/tcpAllow SSH. Do this before enabling ufw on a remote machine.
sudo ufw default deny incomingBlock everything coming in that a rule doesn't allow (this is already the default).
sudo ufw enableSwitch the firewall on, now and at every boot.
sudo ufw allow 8080/tcpOpen a port to everyone.
sudo ufw allow from 192.0.2.0/24 to any port 8080 proto tcpOpen a port to one network only.
sudo ufw insert 1 deny from 192.0.2.10Block an address. It goes in at the top, because ufw uses the first rule that matches and an allow rule higher up would win.
sudo ufw status numberedThe rules with numbers, for deleting.
sudo ufw delete 3Delete a rule by its number from the list above.
sudo ufw delete allow 8080/tcpDelete a rule by writing it out again.
sudo ufw app listThe ready-made profiles installed programs provide (like OpenSSH or Nginx Full), for ufw allow.
sudo firewall-cmd --stateWhether firewalld is running.
sudo firewall-cmd --get-active-zonesWhich zones are in use, and which interfaces and networks are in each.
sudo firewall-cmd --zone=public --list-allEverything a zone allows: services, ports and sources.
sudo firewall-cmd --get-servicesEvery service name firewalld knows (https, ssh, postgresql and so on).
sudo firewall-cmd --zone=public --add-service=httpsOpen a service right now. It's lost at the next reload or reboot, which makes it a safe way to try something.
sudo firewall-cmd --runtime-to-permanentHappy with how it is? Keep the current rules for good.
sudo firewall-cmd --zone=public --add-port=8080/tcp --permanentOpen a port for good. It takes effect after a reload.
--permanent--reloadsudo firewall-cmd --zone=public --remove-service=https --permanentClose a service for good (after a reload).
sudo firewall-cmd --zone=drop --add-source=192.0.2.10 --permanentBlock an address completely, by sending everything from it to the drop zone.
sudo firewall-cmd --zone=trusted --add-source=192.0.2.0/24 --permanentLet one network through to everything. Only for networks you really trust.
sudo firewall-cmd --reloadApply the permanent rules (anything you added without --permanent is dropped).
sudo nft list rulesetEvery rule actually loaded, whichever tool put it there. The final word on what's allowed.
sudo iptables -L -n -v --line-numbersThe rules as iptables sees them, with how many packets each has matched. For older systems and Docker.