This procedure describes how to install and enable a host-based firewall on an Ubuntu server using Uncomplicated Firewall (UFW). UFW is the standard firewall management tool for Ubuntu and provides a simple interface to the underlying Linux netfilter system. This procedure assumes the server is already installed and connected to the network in an enterprise environment.
The purpose of this procedure is to establish a basic host firewall on an Ubuntu server to provide an additional layer of protection in conjunction with existing network firewalls. The steps below cover installation and minimal configuration required to keep administrative access available over SSH while blocking other unsolicited inbound connections. Advanced rule configuration, logging, and integration with enterprise security tools are documented in separate procedures.
Before beginning this procedure, ensure the following requirements are met:
sudo access)Complete the following preparation steps before installing and enabling the firewall:
sudo privileges by running:
sudo whoami
The command should return root.
sudo apt update
Use the following steps to install UFW, set basic default policies, and enable the firewall without interrupting administrative access.
sudo apt install ufw
When prompted, confirm the installation.
sudo ufw status verbose
The output should indicate that the firewall is installed and currently inactive.
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
If the server uses a non-standard SSH port, replace the command above with:
sudo ufw allow <port-number>/tcp
sudo ufw enable
Confirm when prompted. The current SSH session should remain connected if the appropriate rule was added in the previous step.
sudo ufw status verbose
Verify that incoming connections are denied by default and that SSH is listed as allowed.
The Ubuntu server now has a host-based firewall installed and enabled using UFW, with default policies that deny unsolicited incoming traffic and allow outgoing connections while preserving administrative SSH access. Additional rules for application services, logging configuration, and integration with enterprise security controls should be implemented using separate configuration and hardening procedures.