A properly configured firewall is one of the most important layers of security for any internet-facing server. UFW (Uncomplicated Firewall) is a user-friendly front-end for managing iptables rules that ships pre-installed on Ubuntu. Its defaults are sensible: block all incoming connections, allow all outgoing connections. No outside traffic reaches your server unless you explicitly open a port.
This guide covers how to configure a UFW firewall on Ubuntu 18.04, from setting default policies and application profiles to writing allow and deny rules for specific ports, IPs, and subnets.
<strong>Prerequisite:</strong> You need sudo access.
Configure UFW Firewall on Ubuntu: Defaults, SSH, and Application Profiles
If UFW is not installed, add it with:
bashsudo apt install ufw
Check the current status:
bashsudo ufw status verbose
Application profiles. When you install a service with apt, it registers a profile in /etc/ufw/applications.d/. List all available profiles:
bashsudo ufw app list
Use a profile name or a port number interchangeably when writing rules. To see what ports a profile covers:
bashsudo ufw app info 'Nginx...