Install Host Firewall on Ubuntu Server (UFW)

Introduction

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.


Purpose

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.


Prerequisites

Before beginning this procedure, ensure the following requirements are met:

System Requirements

Administrative Requirements


Preparation

Complete the following preparation steps before installing and enabling the firewall:

  1. Confirm Administrative Access
    Log on to the server using a local console or an existing SSH session. Verify that the account you are using has sudo privileges by running:
    sudo whoami
    The command should return root.
  2. Determine Management Access Method
    Identify how administrators will connect to the server (for example, SSH on port 22). This procedure preserves SSH access while enabling the firewall.
  3. Update Package Index
    Ensure the package index is current so that the latest version of UFW can be installed:
    sudo apt update

Install and Enable UFW

Use the following steps to install UFW, set basic default policies, and enable the firewall without interrupting administrative access.

  1. Install UFW Package
    Install the Uncomplicated Firewall package:
    sudo apt install ufw
    When prompted, confirm the installation.
  2. Verify UFW Installation
    Check the current status of UFW:
    sudo ufw status verbose
    The output should indicate that the firewall is installed and currently inactive.
  3. Set Default Policies
    Configure UFW to deny unsolicited incoming traffic and allow outgoing connections by default:
    sudo ufw default deny incoming
    sudo ufw default allow outgoing
  4. Allow SSH Access
    To prevent loss of remote access when the firewall is enabled, allow SSH traffic. For servers using the standard SSH port:
    sudo ufw allow OpenSSH
    If the server uses a non-standard SSH port, replace the command above with:
    sudo ufw allow <port-number>/tcp
  5. Enable UFW
    Enable the firewall and apply the configured rules:
    sudo ufw enable
    Confirm when prompted. The current SSH session should remain connected if the appropriate rule was added in the previous step.
  6. Review Active Rules
    Display the active firewall rules to confirm that defaults and SSH allowances are in place:
    sudo ufw status verbose
    Verify that incoming connections are denied by default and that SSH is listed as allowed.

Completion

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.


©2026 Eric Johnson. All Rights ReservedLinkedIn