Skip to content

Update a VPS and configure its firewall ​

Keep the operating system supported and allow only required traffic. A firewall change must preserve your tested administrative recovery path. These examples use Ubuntu/Debian and UFW.

Before you begin ​

Make a restorable backup. Confirm your actual SSH port and management source address, check any provider firewall, and test the console or other recovery method available for your service. Keep the current SSH session open.

Steps ​

  1. Review available updates and install them in a maintenance window. Read package prompts and plan any service restart or reboot.

    bash
    sudo apt update
    sudo apt upgrade
  2. Inspect current listeners and firewall rules before editing. Ensure UFW is installed if this is the firewall you intend to use.

    bash
    sudo ss -lntp
    sudo ufw status verbose
  3. Allow the actual administrative connection before enabling a deny policy. The following rule is only for default SSH port 22; replace it with your real port, and restrict source addresses if appropriate. A default SSH rule does not cover a custom port.

    bash
    sudo ufw allow 22/tcp
    sudo ufw default deny incoming
  4. Preserve outbound Internet/DNS access. For direct public web hosting, explicitly allow the ports that service uses.

  5. Enable the firewall only after reviewing existing required rules. Test a second administrative session and the website before closing the first session.

    bash
    sudo ufw enable
    sudo ufw status verbose

If something goes wrong ​

If locked out, use the verified recovery route and correct the specific rule. Do not permanently disable the firewall. Check container port publication separately because it can interact with host firewall rules.

Last reviewed ​

2026-10-28