This is part of a series on hosting a website on the Raspberry Pi. Click the Raspberry Pi Webserver in the Blog Series to the right for the complete steps.

UFW is a tool to help set up a firewall with minimal effort.

Let’s start by installing the tool on the Raspberry Pi:

sudo apt install ufw -y

Once the install is finished, edit UFW config file:

sudo nano /etc/default/ufw

Change IPV6=no, we will only accept IPv4. After the change, save and exit nano.

To start UFW, we will enable it:

sudo ufw enable

Setting some default connections to deny all incoming and allow all outgoing:

sudo ufw default deny incoming
sudo ufw default allow outgoing

Allow local access to SSH to pass through before we find ourselves locked out. Remember to change the IP address and port to your numbers. Do a status and compare to what I have below.

sudo ufw limit from 192.168.2.0/24 to any port 2222 proto tcp comment 'Allow SSH'
sudo ufw status

Until we install other programs that need to allow traffic through the firewall, we will conclude with UFW for now.

Check out the next post in the series: Installation of Apache

Share this content: