How Do I Configure Firewall Settings on VPS? Print

  • VPS Firewall, UFW, CSF, Configure Firewall, Open Ports
  • 0

A firewall controls incoming and outgoing traffic to your VPS, blocking unwanted connections while allowing legitimate ones. Here is how to configure two common firewalls.

Option A: UFW (Uncomplicated Firewall) - Great for beginners

  1. Check Status: ufw status

  2. Set Default Policies: ufw default deny incoming and ufw default allow outgoing

  3. Allow Essential Ports:

    • SSH (if you changed the port, use that number): ufw allow 22/tcp

    • Web Traffic (HTTP): ufw allow 80/tcp

    • Secure Web Traffic (HTTPS): ufw allow 443/tcp

    • (Optional) FTP: ufw allow 21/tcp

  4. Enable the Firewall: ufw enable

  5. Verify: ufw status verbose

Option B: CSF (ConfigServer Security & Firewall) - More advanced
CSF is popular on cPanel/WHM servers.

  1. Install: (Instructions vary, usually via root SSH).

  2. Allow/Deny IPs: Edit /etc/csf/csf.allow or /etc/csf/csf.deny.

  3. Open Ports: Edit /etc/csf/csf.conf and look for the TCP_IN and TCP_OUT directives. Add or remove port numbers as needed (e.g., TCP_IN = "20,21,22,25,53,80,110,143,443,465,587,993,995").

  4. Restart CSF: After changes, run csf -r to restart.


Was this answer helpful?

« Back

Powered by WHMCompleteSolution