How to Configure a Firewall on a VDS Server

VDS server, or a virtual dedicated server, gives you high performance and flexibility but also requires that you take responsibility for security management. The firewall configuration is the most critical line of defense against external attacks. So, how do you install a firewall on a VDS server, which rules should you set, and what should you pay attention to?

What Is a Firewall and Why Is It Important?

A firewall monitors, filters and permits or blocks network traffic according to defined rules. Using a firewall on VDS servers protects you from external threats and prevents unwanted traffic from reaching your system.

Where to Start When Installing a Firewall on a VDS Server?

The first step depends on the operating system. For Linux-based VDS servers, the most common tools are iptables, ufw (Uncomplicated Firewall) and firewalld. For Windows-based VDS servers, the built-in Windows Defender Firewall is typically used.

Configuring a Firewall on a Linux VDS Server

🔧 1. Basic UFW Settings

ufw is recommended on distributions like Ubuntu for straightforward, reliable firewall management.

bash
sudo apt install ufw
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp # for SSH access
sudo ufw allow 80/tcp # for HTTP traffic
sudo ufw allow 443/tcp # for HTTPS traffic
sudo ufw enable

With these commands you allow only specific ports and block all other external connections. This activates a basic firewall on your VDS server and reduces the attack surface for unauthorized access.

🔐 2. Advanced Rules with iptables

For users who need more granular control:

bash
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
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 ensure that only clients initiating permitted connections reach the services you explicitly open. Always test iptables changes in a safe session to avoid locking yourself out of the server.

Configuring Firewall on a Windows VDS Server

On Windows servers, firewall configuration can be handled through the graphical interface or using netsh and PowerShell commands for automation.

⚙️ Steps:

→ Go to Control Panel > System and Security > Windows Defender Firewall.

→ From the left menu select Advanced Settings.

→ Add required rules under Inbound Rules (for example, RDP on port 3389 if needed).

→ Check whether unnecessary services are exposed to the public internet and disable or restrict them.

Which Ports Should Be Allowed?

A typical VDS firewall configuration usually allows the following ports only when required:

  • 22 → SSH (for Linux administration)

  • 80 → HTTP (web server)

  • 443 → HTTPS (secure web traffic)

  • 3306 → MySQL (if required, should be open only for internal access)

  • 21/20 → FTP (prefer SFTP whenever possible)

  • 3389 → RDP (should be restricted to specific IP addresses)

Extra Security Tips

  • 🔐 Limit SSH access by IP address whenever possible.

  • 🛡️ Use additional protections like port knocking or fail2ban to block repeated malicious attempts.

  • 🔄 Review your firewall rules regularly and remove unused openings.

  • 📜 Analyze logs to track which IPs are trying to access your server and detect suspicious behavior early.

  • 📍 For cloud control panels (for example Proxmox, VirtPanel, Plesk), configure firewall rules both at the OS level and at the cloud/network layer for layered protection.

Benefits of Using a Firewall on a VDS Server

  • It forms the first line of defense against attacks such as DDoS.

  • It ensures only authorized traffic reaches your system.

  • It helps preserve performance because malicious traffic cannot drain system resources.

  • It supports legal and regulatory compliance (for example data protection requirements) by controlling access and logging events.

Firewall Is the Foundation of Security

Although VDS servers offer significant advantages in performance and control, that freedom comes with responsibility. A poorly configured firewall can leave your system exposed to malicious access. Therefore, firewall configuration should be the first and indispensable step when setting up a VDS.

Create rules tailored to your server’s operating system, the applications it hosts, and your intended use. Update these rules periodically to maintain proactive security and keep your VDS server protected against evolving threats.