Setting up a firewall is one of the simplest ways to strengthen your server’s security. In this guide, you’ll learn how to configure a firewall for your cloud-based server step by step. You’ll also see how to manage inbound and outbound traffic and apply smart port management to keep attackers out while keeping your services reachable.
What Is a Firewall
A firewall controls what enters or leaves your server. When configured well, it forms a strong barrier between your system and unwanted traffic. It is a network security system that monitors, filters, and controls incoming and outgoing traffic based on predefined rules.
In the following steps, you’ll learn how to define essential services, set rules in your cloud provider’s dashboard, and configure both Linux and Windows server firewalls.
Step 1: Define What You Need to Protect
Start by mapping out which services need to be accessible. This helps you avoid exposing unnecessary ports.
A common setup includes:
- Port 22 for SSH
- Port 80 for HTTP
- Port 443 for HTTPS
Everything else should stay blocked. This improves security and reduces exposure to attacks.
Step 2: Configure Firewall Rules in Your Cloud Dashboard
Next, visit your cloud provider’s control panel. Then, open the firewall or security group section tied to your server. Here you manage inbound and outbound traffic. Keep your rules simple and open only for what you need. If possible, allow specific IP addresses instead of broad ranges. This gives you more control and reduces risks.
Since most interfaces use point-and-click options, you can complete this step without terminal commands.
Step 3: Linux Firewall Setup with iptables
If your server runs Linux, you will likely use iptables to manage rules. Start by checking your current rule set:
iptables -L If the output looks empty, your firewall is not doing much yet. So, let’s add key rules. Allow SSH, HTTP and HTTPS using these commands:
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp --dport 443 -j ACCEPT These rules open the essential ports. Then, set a default policy to block everything else:
iptables -P INPUT DROP Make sure you have already allowed SSH. Otherwise, you may lock yourself out.
Make Your Linux Firewall Rules Persistent
iptables rules disappear after reboot unless you save them. To make them persistent, install the necessary tool:
For Debian/Ubuntu:
apt-get install iptables-persistent For CentOS:
yum install -y iptables-services Then save your active rules:
iptables-save > /etc/iptables/rules.v4 This ensures your configuration returns after every restart.
Step 4: Windows Firewall Setup
Windows users can configure rules visually. Open Windows Firewall with Advanced Security, then go to Inbound Rules.
Here you can:
- Allow RDP on port 3389
- Enable or disable HTTP and HTTPS
- Remove rules for unused services
Review your rules carefully so your firewall stays clean and effective.
Step 5: Test Your Configuration
After setting up your firewall, always test your ports. From your local machine, try:
curl http://your-server-ip If it returns a response, HTTP traffic is working. You can also run nmap to scan open ports and confirm your rule set is correct.
Step 6: Back Up and Maintain Your Firewall Configuration
Backups make it easy to recover from mistakes. On Linux, save your full firewall configuration with:
iptables-save > /root/iptables_backup To restore it, run:
iptables-restore < /root/iptables_backup Review your rules monthly. Remove old entries and keep your configuration tidy to maintain strong security.
Watch Our YouTube Video on Firewalls for Cloud-Based Servers
If you prefer a visual walk-through, we have a YouTube Video ready for you.
Final Thoughts
A firewall is more than a simple on or off switch. It is a traffic filter that monitors, allows, blocks, or logs data based on your rules. In a virtualized environment, it protects the host, the hypervisor, and each virtual machine from unwanted access. By defining your exposed services, configuring cloud firewall rules, setting up iptables on Linux, and using Windows Firewall, you create a layered defense strategy. Combined with regular testing, backups, and reviews, this gives your cloud server a strong, controlled security perimeter.