Ubuntu firewall management tool
sudo ufw [options] [rule/command]
iptables operations.enable: Enable the firewall and set it to start at boot.disable: Disable the firewall.reload: Reload firewall rules (without interrupting existing connections).reset: Reset all rules to the initial state.allow <rule>: Allow a specified rule (e.g., port, service).deny <rule>: Deny a specified rule.status: Show the firewall status and list of rules.<port>: Port number (e.g., 22, 80/tcp).<protocol>: Protocol type (tcp or udp).comment <text>: Add a comment to a rule (must be used with allow/deny).--dry-run: Show rule changes only, without actually applying them.0 on successful execution.# Enable firewall
sudo ufw enable
# Disable firewall
sudo ufw disable
# View firewall status
sudo ufw status
# Allow default SSH port (22/tcp)
sudo ufw allow ssh
# Allow port 8080 for TCP and add a comment
sudo ufw allow 8080/tcp comment "Web Server"
# Deny access from 192.168.1.5
sudo ufw deny from 192.168.1.5
# Deny port 53 for UDP
sudo ufw deny 53/udp
# Show numbered rule list (useful for deletion)
sudo ufw status numbered
# Delete the 3rd rule
sudo ufw delete 3
# Reset all rules
sudo ufw reset
sudo.sudo ufw logging on; logs are located at /var/log/ufw.log.
/etc/services (e.g., http, ssh).