What Is a Firewall? How to Set Up One on Your PieBox
Learn what a firewall is and how to configure UFW on an Ubuntu cloud VPS. Launch a PieBox server and secure it step by step.
Subhajit Chatterjee
5 min read

Imagine renting a house and leaving the front door open all day. Anyone could walk in, look around, or even take something.
That's pretty much what happens when you run a server without properly configuring its firewall.
A server connected to the internet can receive requests from anywhere in the world. Some requests are legitimate, like visitors opening your website. Others might be automated bots scanning for vulnerable services, exposed databases, or open ports.
This is where a firewall comes in.
In this guide, we'll understand what a firewall does, launch a cloud VPS using PieBox, and configure a firewall on Ubuntu using UFW.
You don't need to be a security expert to follow along.
What is a firewall?
A firewall is a security system that monitors and controls incoming and outgoing network traffic based on predefined rules.
Think of it as a security guard standing at the entrance of your building.
The guard checks who's allowed to enter and who isn't. A firewall does something similar for your server.

For example:
- Allow visitors to access your website through port 80 (HTTP).
- Allow encrypted website traffic through port 443 (HTTPS).
- Allow you to connect to your server through SSH on port 22.
- Block access to database ports that shouldn't be publicly accessible.
Without a firewall, services running on your server may be reachable from the internet, depending on their network configuration.
A firewall helps you decide what should be accessible and what should stay private.
Step 1: Launch a cloud VPS using PieBox
Before configuring a firewall, we need a server.
We'll use PieBox, Pie.host's cloud VPS service, to launch an Ubuntu server.
If you don't already have an account, visit Pie.host and create one.
- Open the Pie.host dashboard
- Click Launch > PieBox > a server configuration based on your requirements, 2GB ram will work for demo.
- Select Ubuntu as your operating system.
- Configure your server and launch the instance.
- Once it's ready, note down its public IP address and SSH credentials.
That's it. You now have your own cloud server.
Step 2: Connect to your VPS
Open your terminal on macOS or Linux. On Windows, you can use PowerShell or Windows Terminal.
Run:
ssh root@YOUR_SERVER_IP
Replace YOURSERVERIP with the public IP address of your PieBox instance.
If you're using an SSH key, specify it with:
ssh -i ~/.ssh/your_key root@YOUR_SERVER_IP
Once connected, you'll have terminal access to your VPS.
Step 3: Install UFW

We'll use UFW, which stands for Uncomplicated Firewall.
It's a straightforward firewall management tool available on Ubuntu. Instead of manually writing complex firewall rules, you can manage access using simple commands.
First, update your package list:
apt update
Install UFW:
apt install ufw -y
Check whether it's installed:
ufw version
Step 4: Configure your firewall rules
Before enabling the firewall, we need to decide which ports should be accessible.
For this example, we'll allow:
| Port | Protocol | Purpose |
|---|---|---|
| 22 | TCP | SSH access |
| 80 | TCP | HTTP traffic |
| 443 | TCP | HTTPS traffic |
First, allow SSH:
ufw allow 22/tcp
This is important. If you enable the firewall without allowing SSH, you could lock yourself out of your server.
Next, allow HTTP:
ufw allow 80/tcp
And HTTPS:
ufw allow 443/tcp
You can also use application profiles where available:
ufw allow OpenSSH
Now let's configure the default firewall policies.
Block incoming connections unless explicitly allowed:
ufw default deny incoming
Allow outgoing connections:
ufw default allow outgoing
This means your server can initiate connections to external services, but unsolicited incoming connections will be blocked unless you've explicitly allowed them.
Step 5: Enable the firewall
Now that our rules are ready, enable UFW:
ufw enable
You'll see a warning that enabling the firewall may disrupt existing SSH connections.
Since we've already allowed SSH, you can proceed.
Check the firewall status:
ufw status
You should see something similar to:
Status: active
To Action From
-- ------ ----
22/tcp ALLOW Anywhere
80/tcp ALLOW Anywhere
443/tcp ALLOW Anywhere
Congratulations! Your VPS now has a basic firewall configured.
Step 6: Test your firewall
Let's verify that everything is working.
Check the active rules:
ufw status verbose
You can also inspect listening services:
ss -tulpn
This command shows which ports your server applications are listening on.
Remember, opening a port in UFW doesn't automatically start a service on that port. Similarly, a service listening on a port doesn't mean it is publicly accessible if the firewall blocks it.
For example, if you run a web application on port 3000, it won't be publicly accessible until you explicitly allow it:
ufw allow 3000/tcp
However, if you're running a production application, it's usually better to put Nginx or another reverse proxy in front of it and keep the application port private.
Step 7: Remove firewall rules when needed
Suppose you temporarily allowed port 3000 and now want to close it.
Simply run:
ufw delete allow 3000/tcp
To see numbered firewall rules:
ufw status numbered
You can delete a specific rule by its number:
ufw delete 4
Be careful when deleting rules, especially those related to SSH.
A few firewall security tips
Configuring UFW is a good starting point, but there's more to server security.
Here are a few things worth doing:
1. Don't expose everything
Only open ports that your applications actually need. Your MySQL, Redis, and other internal services shouldn't be publicly accessible unless there's a specific reason.
2. Secure SSH access
Use SSH keys instead of passwords where possible. Consider disabling password authentication after confirming that key-based access works.
3. Keep your server updated
Run regular system updates:
apt update && apt upgrade -y
4. Don't rely on a firewall alone
A firewall cannot protect an application from every vulnerability. Keep your software updated, use strong authentication, and monitor your server.
5. Consider cloud-level firewall rules too
Host-level firewalls like UFW and cloud firewalls can complement each other. If your VPS provider offers network-level firewall controls, you can use them as an additional security layer.
Conclusion
A firewall is one of the simplest but most important security measures you can configure on a cloud server.
The good news is that you don't need expensive security software or complicated configurations to get started.
With a cloud VPS from PieBox and a few UFW commands, you can control which services are accessible from the internet and reduce unnecessary exposure.
If you're looking to launch your own VPS, host applications, run backend services, or experiment with Linux infrastructure, give PieBox a try.
Launch your own cloud VPS with PieBox: https://piehost.com/piebox


Comments
No comments yet. Questions and corrections are welcome.