tips
32 tips Ufw
One command, setting or habit at a time about Ufw: what it does, the line to copy and a caveat or two.
ufw rules 29
-
After you edit or create a ufw application profile, this command makes the firewall use the new version.
sudo ufw app update all -
Shows everything ufw has actually loaded, which is handy when a rule does not behave as expected.
sudo ufw show raw -
IPsec uses protocols 50 and 51, so a normal port rule does not cover it.
sudo ufw allow to 10.0.0.1 proto esp -
Keepalived uses VRRP, protocol 112, which ufw only accepts in the full rule syntax.
sudo ufw allow to 224.0.0.0/24 from 10.0.0.1 proto vrrp -
Lists listening ports with their program and the ufw rule that applies.
sudo ufw show listening -
Makes sure ufw writes rules for IPv6 as well as IPv4.
grep IPV6 /etc/default/ufw -
Combines a list of ports and port ranges into a single firewall rule.
sudo ufw allow proto tcp from any to any port 80,443 comment 'web' -
Blocks outgoing connections from the server to a chosen address or network.
sudo ufw deny out to 203.0.113.0/24 -
Adds masquerading and forwarding so VPN clients can reach the internet through the server.
*nat -
Defines a named profile for your own service so rules refer to a name.
[Jellyfin] -
Shows why adding the protocol to a port rule keeps the opening as small as needed.
sudo ufw allow 8080 -
Logs connections that match one specific rule, without raising the global log level.
sudo ufw allow log 22/tcp -
Explains the fields in a ufw log line so you can see what was blocked.
sudo journalctl -k --since '1 hour ago' | grep 'UFW BLOCK' -
Refuses a connection with an immediate reply instead of silently dropping it.
sudo ufw reject 8080/tcp -
Wipes all firewall rules back to the defaults and saves the old rule files first.
sudo ufw reset -
Adds a short note to a firewall rule so you remember why the port is open.
sudo ufw allow 8096/tcp comment 'Jellyfin' -
Lists the firewall rules you have added so you can check them before turning ufw on.
sudo ufw show added -
Removes a firewall rule by its number from the numbered status list.
sudo ufw status numbered -
Allows SSH but blocks any address that opens six or more connections in thirty seconds.
sudo ufw limit ssh -
Adds a rule at a chosen position so it is evaluated first.
sudo ufw insert 1 deny from 203.0.113.7 -
Allows traffic arriving on one network interface, such as a VPN.
sudo ufw allow in on tailscale0 -
Edits ufw's rule file to stop the host from answering pings.
sudo ufw reload -
Shows what a ufw command would change without making the change.
sudo ufw --dry-run allow 8080/tcp -
Prints active state, default policies and log level with the rule list.
sudo ufw status verbose -
Writes firewall rules for traffic that is forwarded between interfaces.
sudo ufw route allow in on wg0 out on eth0 to 192.168.1.0/24 -
Explains why ufw misses published container ports and how to avoid it.
docker run -d -p 127.0.0.1:8080:80 nginx -
Sets what ufw does with traffic that none of your rules match.
sudo ufw default deny incoming -
Sets how many firewall events ufw writes to its log file.
sudo ufw logging medium -
Removes a firewall rule by naming it rather than looking up its number.
sudo ufw delete allow 80/tcp
Access and security 2
-
Enables the firewall without the interactive question, for setup scripts.
ufw --force enable -
Opens a port only to one source network instead of to everyone.
sudo ufw allow from 192.168.1.0/24 to any port 5432 proto tcp
Nginx Proxy Manager 1
-
Uses named service profiles to open the right ports with one word.
sudo ufw app list
Nothing in this filter yet.