Security
UFW CLI
UFW commands for simple firewall management on Ubuntu.
32 commands
Windows
MacOS
Linux
#firewall
#ubuntu
Basic Control
Enable the firewall
sudo ufw enable
Disable the firewall
sudo ufw disable
Show firewall status and rules
sudo ufw status
Show detailed firewall status
sudo ufw status verbose
Show rules with numbers
sudo ufw status numbered
Reset all rules to defaults
sudo ufw reset
Allow & Deny
Allow incoming SSH traffic
sudo ufw allow 22
Allow incoming HTTP TCP traffic
sudo ufw allow 80/tcp
Allow incoming HTTPS TCP traffic
sudo ufw allow 443/tcp
Deny incoming MySQL traffic
sudo ufw deny 3306
Allow traffic from subnet
sudo ufw allow from 192.168.1.0/24
Deny traffic from specific IP
sudo ufw deny from 10.0.0.5
sudo ufw allow in on eth0 to any port 80 # Allow port 80 on specific interface
Application Profiles
List available application profiles
sudo ufw app list
Show details of app profile
sudo ufw app info "Nginx Full"
Allow traffic for OpenSSH profile
sudo ufw allow "OpenSSH"
Allow HTTP and HTTPS for Nginx
sudo ufw allow "Nginx Full"
Remove rule for app profile
sudo ufw delete allow "Nginx Full"
Logging
Enable firewall logging
sudo ufw logging on
Disable firewall logging
sudo ufw logging off
Set logging level to medium
sudo ufw logging medium
Set logging level to high
sudo ufw logging high
Advanced Rules
sudo ufw allow proto tcp from 192.168.1.0/24 to any port 22 # Allow SSH from subnet
sudo ufw allow from any to any port 60000:61000 proto udp # Allow UDP port range
Delete rule by number
sudo ufw delete 3
Insert rule at position 1
sudo ufw insert 1 allow from 10.0.0.1
Set default policy to deny incoming
sudo ufw default deny incoming
Set default policy to allow outgoing
sudo ufw default allow outgoing
sudo ufw route allow in on eth0 out on eth1 # Allow forwarded traffic between interfaces
Quick Commands
Show firewall rules with numbers
sudo ufw status numbered
Allow traffic from specific subnet
sudo ufw allow from 192.168.1.0/24
Set default policy to deny incoming traffic
sudo ufw default deny incoming