How to setup a UFW firewall on Ubuntu 18.04 LTS server

How to setup a UFW firewall on Ubuntu 18.04 LTS server

UFW (Uncomplicated Firewall) is a firewall utility that makes it easy to configure and manage the firewall on a Ubuntu 18.04 LTS server. Here is how you can set up a UFW firewall on Ubuntu 18.04 LTS server:

  1. Install UFW:

UFW is pre-installed on Ubuntu 18.04 LTS, so you don't need to install it. If it is not installed, you can install it using the following command:

refer to:‮uttual‬ri.com
sudo apt-get install ufw
  1. Set the default policies:

By default, UFW allows all incoming and outgoing traffic. To set the default policies for incoming and outgoing traffic, run the following commands:

sudo ufw default deny incoming
sudo ufw default allow outgoing

This will deny all incoming traffic and allow all outgoing traffic.

  1. Allow specific services or ports:

To allow specific services or ports, you can use the ufw allow command. For example, to allow SSH connections, use the following command:

sudo ufw allow ssh

To allow HTTP and HTTPS connections, use the following command:

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

You can also specify a specific IP address or IP range to allow or deny access. For example, to allow access from a specific IP address, use the following command:

sudo ufw allow from <ip-address>
  1. Enable UFW:

After you have set the default policies and allowed specific services or ports, you can enable UFW using the following command:

sudo ufw enable

This will activate the firewall and apply the rules that you have set.

  1. Check the status of UFW:

To check the status of UFW and view the firewall rules, you can use the ufw status command. This will show the active firewall rules and the default policies for incoming and outgoing traffic.

Created Time:2017-10-29 22:08:38  Author:lautturi