Ubuntu UFW Firewall Configuration
Advancedv1.0.0
Configure Ubuntu's UFW firewall — enable default deny, allow specific ports and services, create application profiles, rate limiting, and logging for production server security.
Content
Overview
UFW (Uncomplicated Firewall) is Ubuntu's default firewall management tool. It provides a simple interface to iptables/nftables for managing network access rules. Every production Ubuntu server should have UFW enabled with a default deny policy.
Why This Matters
- -An unprotected server is scanned within minutes of going online
- -Default deny blocks all unexpected traffic automatically
- -UFW makes firewall management accessible without iptables expertise
Configuration
Step 1: Set Default Policies
Step 2: Allow Essential Services
Step 3: Restrict by Source IP
Step 4: Rate Limiting for SSH
Step 5: Enable UFW
Managing Rules
Best Practices
- -ALWAYS allow SSH before enabling UFW (or you lock yourself out)
- -Use default deny incoming — whitelist only what you need
- -Restrict database ports to specific source IPs
- -Use UFW application profiles (ufw app list) when available
- -Enable logging to detect scanning attempts
- -Use rate limiting on SSH to slow brute force attacks
- -Test rules on staging before applying to production
Common Mistakes
- -Enabling UFW without allowing SSH first (locked out of server)
- -Allowing 0.0.0.0/0 access to database ports (should be specific IPs)
- -Not enabling UFW at all (relying on "security through obscurity")
- -Forgetting to open ports after deploying new services
- -Using allow instead of limit for SSH (no brute force protection)
FAQ
Discussion
Loading comments...