Knowledge Base / VPS Hosting / Setting Up a Firewall on Your VPS

Setting Up a Firewall on Your VPS

Setting Up a Firewall with UFW

By default your VPS accepts all incoming connections. Setting up a firewall is one of the most important security steps after provisioning.

Using UFW (Uncomplicated Firewall)

UFW is pre-installed on Ubuntu and Debian. If it is not present, install it:

apt install ufw

Basic Configuration

# Allow SSH (critical — do this BEFORE enabling UFW)
ufw allow 22/tcp

# Allow HTTP and HTTPS
ufw allow 80/tcp
ufw allow 443/tcp

# Enable the firewall
ufw enable

# Check status
ufw status verbose

Common Rules

  • MySQL: ufw allow 3306/tcp
  • Custom port: ufw allow 8080/tcp
  • Allow IP only: ufw allow from 1.2.3.4 to any port 22
  • Delete a rule: ufw delete allow 3306/tcp

Important Warning

Always allow SSH (port 22) before enabling UFW. If you lock yourself out, open a support ticket and request a firewall reset or console access.

Blocking All Incoming by Default

ufw default deny incoming
ufw default allow outgoing

This blocks all inbound traffic except what you explicitly allow — the safest approach for production servers.

Was this article helpful?

Still need help?

Our support team is here for you 24/7.

Open a Support Ticket