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
Review available updates and install them in a maintenance window. Read package prompts and plan any service restart or reboot.
bashsudo apt update sudo apt upgradeInspect current listeners and firewall rules before editing. Ensure UFW is installed if this is the firewall you intend to use.
bashsudo ss -lntp sudo ufw status verboseAllow 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.
bashsudo ufw allow 22/tcp sudo ufw default deny incomingPreserve outbound Internet/DNS access. For direct public web hosting, explicitly allow the ports that service uses.
Enable the firewall only after reviewing existing required rules. Test a second administrative session and the website before closing the first session.
bashsudo 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.
Related articles
Last reviewed
2026-10-28
