Overview¶
UFW (Uncomplicated Firewall) is a user-friendly interface for managing firewall rules using iptables. It simplifies firewall configuration and is commonly used for:
-
Securing servers
-
Controlling network traffic
-
Restricting access to services
-
Basic cybersecurity defense
By default, UFW is disabled.
Installation¶
Explanation
Installs the UFW firewall package on the system.
Enable / Disable and Status¶
Enable UFW¶
Explanation
-
Activates firewall
-
Applies rules
-
Enables at startup
Disable UFW¶
Explanation
Stops firewall and disables it at startup.
Check Status¶
Verbose Status¶
Explanation
Displays detailed information including default policies.
Numbered Rules¶
Explanation
Shows rules with numbers for easy deletion.
Default Policies¶
Allow All Incoming Connections¶
Deny All Incoming Connections (Recommended)¶
Allow All Outgoing Connections¶
Deny All Outgoing Connections¶
Best Practice¶
Explanation
Blocks unauthorized incoming traffic while allowing outbound connections.
Allow and Deny Rules¶
List Available Applications¶
Allow a Service¶
Explanation
Allows SSH connections.
Deny a Service¶
Port-Based Rules¶
Allow Port¶
Allow TCP Port¶
Allow UDP Port¶
Deny Port¶
Deny TCP/UDP Ports¶
Advanced Rules¶
Allow from Specific IP¶
Allow from Subnet¶
Allow Specific IP to Specific Port¶
Allow with Protocol¶
Deny Rules¶
Same syntax applies using deny instead of allow.
Deleting and Resetting Rules¶
Delete Rule by Number¶
Explanation
Deletes rule number 1 from the list.
Reset Firewall¶
Explanation
-
Removes all rules
-
Resets to default state
-
Use carefully
Practical Examples¶
Secure Server Setup¶
Allow Web Traffic¶
Restrict SSH to Specific IP¶
Important Notes¶
-
Always allow SSH before enabling UFW to avoid lockout
-
Use numbered rules for easy management
-
Prefer restrictive rules (deny by default)
-
Test rules before deploying in production
Summary Table¶
| Command | Purpose |
|---|---|
ufw enable |
Enable firewall |
ufw disable |
Disable firewall |
ufw status |
Check status |
ufw allow |
Allow traffic |
ufw deny |
Deny traffic |
ufw delete |
Remove rule |
ufw reset |
Reset firewall |
ufw default |
Set default policy |
Conclusion¶
UFW is a powerful yet simple firewall tool that helps:
-
Secure Linux systems
-
Control incoming and outgoing traffic
-
Prevent unauthorized access
Mastering UFW is essential for system administrators and cybersecurity professionals to maintain a secure environment.