How to Set Up a firewall with UFW on Ubuntu?

How to Set Up a firewall with UFW on Ubuntu?

Setting up a firewall using Uncomplicated Firewall (UFW) on Ubuntu is relatively straightforward.
UFW provides a user-friendly interface for managing iptables, the default firewall management tool for Linux.

Here`s a step by step manual to putting in a simple firewall the usage of UFW on Ubuntu:

  1. Check UFW Status: First, ensure that UFW is installed and not currently running.
    You can check its status with the following command:

    sudo ufw status

    If UFW is not installed, you can install it by running:

    sudo apt update
    sudo apt install ufw
  2. Set Default Policies: Decide on your default policies for incoming and outgoing traffic.
    These policies determine whether traffic is allowed or denied if no specific rules match.
    The typical default policy is to deny all incoming traffic and allow all outgoing traffic.
    You can set these policies with the following commands:

    sudo ufw default deny incoming
    sudo ufw default allow outgoing
  3. Allow SSH (Optional): If you’re connecting to your Ubuntu server remotely via SSH, you need to allow SSH traffic to access the server.
    Otherwise, you might get locked out. You can allow SSH traffic with the following command:

    sudo ufw allow ssh

    This command will allow SSH traffic on the default SSH port (22).
    If you’re using a different port for SSH, replace ssh with your custom port number.

  4. Allow Other Necessary Services: Similarly, you may need to allow traffic for other services your server provides, such as HTTP (port 80) or HTTPS (port 443).
    You can allow these services using commands like:

    sudo ufw allow http
    sudo ufw allow https

    Replace http and https with the appropriate service names if you’re using non-standard ports.

  5. Enable UFW: Once you’ve set up your firewall rules, enable UFW to start enforcing them:
    sudo ufw enable
  6. Check Status: After enabling UFW, you can verify the status to ensure that the firewall is active and configured correctly:
    sudo ufw status

    This command will show a precis of the basic firewall rules, which include the default guidelines and any explicitly allowed services.

That’s it! You’ve now set up a basic firewall using UFW on your Ubuntu server.
Make certain to check your firewall policies to make sure they`re running as expected, in particular when you have complicated community configurations or particular protection requirements.

Post Your Comment

Free Migration Assistance

If you need assistance with migrating your current data from another provider, we would be more than happy to assist.