ufw Command
ufw, or Uncomplicated Firewall, is a user-friendly front-end for managing iptables. It is the default firewall management tool on Ubuntu and is designed to make common firewall tasks easy without needing to learn the complex syntax of iptables.
Basic Management
Check Firewall Status
sudo ufw statusShows whether the firewall is active or inactive. To see the configured rules, use sudo ufw status verbose.
Enable the Firewall
sudo ufw enableActivates the firewall. It will typically start on boot after being enabled.
Disable the Firewall
sudo ufw disableDeactivates the firewall.
Managing Rules
Allow a Service by Name
sudo ufw allow sshAllows incoming traffic for a known service. ufw knows the default ports for many services (e.g., ssh is 22, http is 80). This is the same as sudo ufw allow 22.
Allow a Specific Port
sudo ufw allow 8080/tcpAllows incoming traffic on a specific port and protocol. If you don't specify a protocol, the rule applies to both TCP and UDP.
Deny a Port
sudo ufw deny 3306Blocks all incoming traffic on the specified port (e.g., the default MySQL port).
Allow Traffic from a Specific IP
sudo ufw allow from 123.45.67.89Allows all incoming traffic from a specific IP address.
Delete a Rule
sudo ufw delete allow sshDeletes a previously added rule. You must specify the exact rule you want to remove.