Set Up a Firewall on Linux with UFW: Allow SSH, HTTP

Learn to set up a simple firewall on Linux with UFW, allowing SSH and HTTP while blocking other traffic. Step-by-step guide for beginners.

Key takeaway: follow the security steps carefully and prefer AES-256 encryption where available.

Understanding Firewalls and UFW A firewall is a network security device that monitors and controls incoming and outgoing network traffic based on predetermined security rules. UFW, or Uncomplicated Firewall, is a user-friendly command-line interface for managing firewall rules on Linux. It simplifies complex iptables commands and is ideal for beginners. Before You Start To set up a firewall with UFW, you need a Linux-based system with administrative privileges. This guide assumes you're using a Debian-based distribution like Ubuntu, but UFW is available on many others. Familiarity with basic command-line operations is helpful but not necessary. Warnings Incorrect firewall configuration can result in losing access to your server, especially if configuring remotely. Always ensure you have physical or console access as a backup. Be cautious with firewall rules that might block necessary services. Installing UFW 1. Open your terminal. 2. Update your package lists: sudo apt update 3. Install UFW if it's not already installed: sudo apt install ufw Checking UFW Status Before configuring, check if UFW is enabled: 1. Run: sudo ufw status 2. If UFW is inactive, activate it using: sudo ufw enable Allowing SSH and HTTP 1. Allow SSH to ensure you don't lose remote access: sudo ufw allow ssh This command permits traffic on port 22, the default port for SSH. 2. Allow HTTP traffic: sudo ufw allow http This command opens port 80, used by web servers to deliver content. Denying All Other Traffic 1. Configure UFW to deny all other incoming traffic: sudo ufw default deny incoming 2. To allow all outgoing traffic (common practice), execute: sudo ufw default allow outgoing 3. Reload UFW to apply changes: sudo ufw reload Verifying Firewall Rules 1. Check the active rules to ensure they are configured correctly: sudo ufw status verbose This displays all active rules and their status. Additional Tips - Consider allowing HTTPS (port 443) if you plan to secure web traffic. - If using Astraguard VPN or similar services, ensure their ports are open. Key Takeaways • UFW simplifies firewall management on Linux. • Always allow SSH before setting restrictive rules to avoid lockout. • Default settings should deny incoming traffic and allow outgoing. • Verify all rules using `ufw status` to ensure correct configuration. • Modify rules based on server needs, such as allowing HTTPS. FAQs Q: Can I use UFW with other Linux distributions? A: Yes, UFW is available on most Linux distributions. Q: …

Related reading

VPN guides and use cases

More blog articles · VPN plans