No KYC · KVM in Hong Kong, Tokyo and Singapore at one price · Pay in BTC, USDT, USDC, ETH, SOL, LTC, XMR
Language: English
Build a server

Guide · Debian 13 and Ubuntu 24.04 · checked 16 November 2026

How do you set up a UFW firewall on a VPS?

This is how to set up a UFW firewall on a VPS running Debian 13 or Ubuntu 24.04, without cutting your own SSH session.

Last updated: · 5 min read

Quick answer

How do you set up a UFW firewall on a VPS?

To set up a UFW firewall on a VPS, install ufw, deny incoming traffic by default, allow OpenSSH, open 80 and 443 only for a website, then run ufw enable. Six commands are enough. On a JadeKVM server, outbound port 25 is already closed, so UFW only needs to guard the inbound side.

In brief
  • Allow SSH before enabling: otherwise the firewall drops your own session.
  • Default deny incoming, allow outgoing: the safe base for a single server.
  • ufw limit OpenSSH slows password-guessing bots at the firewall level.
  • Docker warning: published container ports skip UFW rules.

How to set up a UFW firewall on a VPS in 6 steps?

Run each command as a sudo user. Ubuntu 24.04 ships ufw; on Debian 13 you install it first.

  1. Install ufw

    Run sudo apt install ufw. The package is small and has no service to tune.

  2. Set the defaults

    Deny incoming and allow outgoing with two ufw default commands.

  3. Allow SSH

    Run sudo ufw limit OpenSSH. It allows port 22 and slows repeat connections.

  4. Open service ports

    Allow 80 and 443 for a website, or the single port your app needs.

  5. Enable the firewall

    Run sudo ufw enable and confirm with y. Rules load now and at every boot.

  6. Read the status

    Run sudo ufw status verbose and check that only the ports you chose are listed.

Which UFW rule fits which service?

Common UFW rules on a VPS, the port each one opens and when to use it
ServiceRulePortOpen it when
SSHufw limit OpenSSH22/tcpAlways, before ufw enable
Websiteufw allow 80,443/tcp80 and 443/tcpYou run nginx or another web server
Telegram webhookufw allow 8443/tcp8443/tcpYour bot uses a webhook on 8443
WireGuardufw allow 51820/udp51820/udpYou run a WireGuard endpoint
Databasenone3306 or 5432Never to the world; use SSH tunnels

Why allow SSH before you run ufw enable?

Because ufw enable applies the default deny at once, and a missing SSH rule closes the door you are standing in. The tool warns that existing SSH connections may drop. Answer y only after ufw show added lists OpenSSH.

If it goes wrong, a dashboard reboot does not help: the rules persist. Reboot, reinstall and delete requests are sent from the dashboard and carried out by a person; a reinstall wipes the disk. Write to support, and test changes in a second window next time.

A UFW base for a web server
sudo apt install -y ufw
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw limit OpenSSH
sudo ufw allow 80,443/tcp
sudo ufw show added
sudo ufw enable
sudo ufw status verbose

Which is the best UFW setup for an Asia VPS in 2026?

The same short list as anywhere: SSH limited, web ports open if needed, everything else denied. A server in Hong Kong, Tokyo or Singapore draws the same scans as one in Europe. UFW does not change latency either.

JadeKVM read WonderNetwork's public pings on 16 November 2026: Singapore sits 15 ms from Jakarta and 8 ms from Kuala Lumpur. Latency figures on JadeKVM pages are public averages measured by WonderNetwork between its own servers on 16 November 2026; they show how far apart the cities sit on the network, not a promise about any one JadeKVM server. The firewall adds no measurable delay to those trips. To measure your own path, see how to test latency to your server.

How do you delete or change a UFW rule?

List the rules with numbers, then delete by number. sudo ufw status numbered prints each rule with an index. sudo ufw delete 3 removes the third one. IPv6 copies show as separate lines, so delete both.

To allow one address only, for example your office, use sudo ufw allow from 198.51.100.7 to any port 22 proto tcp. Then remove the general SSH rule.

Does Docker ignore UFW rules?

Yes: Docker writes its own iptables rules, so a published container port is open even if UFW denies it. Docker's own documentation says so. Bind containers to 127.0.0.1 and put nginx in front, or filter in the DOCKER-USER chain. The guide on how to install Docker on a VPS shows the safe pattern.

What else should sit next to UFW?

fail2ban for the SSH journal, and keys-only login. UFW counts connections; fail2ban reads failed logins and bans their source. Together with the steps in how to secure a Linux VPS, they cover the usual attacks. Outbound port 25 is closed on every server; send mail through a mail provider on port 465 or 587.

Questions about UFW on a VPS

Is UFW installed on Ubuntu 24.04?

Yes, but it is inactive until you run ufw enable. On Debian 13, install it with apt first.

Does UFW work with IPv6?

Yes. IPV6=yes is the default in /etc/default/ufw, so each rule gets an IPv6 twin. JadeKVM servers have a routed IPv6 /64.

Which is better: UFW or firewalld?

On Debian and Ubuntu, UFW is the native and simpler choice. Firewalld is the norm on AlmaLinux and Rocky Linux.

Can UFW stop a DDoS attack?

No. A large flood saturates the link before UFW sees it. UFW closes ports; it does not absorb traffic.

How do I turn UFW off for a test?

Run sudo ufw disable. The rules stay saved, and ufw enable brings them back.

Verdict
  • Allow OpenSSH, deny the rest, enable: that order is the whole trick.
  • Bind Docker ports to 127.0.0.1, because Docker skips UFW.
Sources (4)
  1. ufw(8) manual page, Ubuntu 24.04 — Canonical (read 2026-11-16)
  2. Firewalls, Ubuntu Server documentation — Canonical (read 2026-11-16)
  3. Packet filtering and firewalls, Docker Engine documentation — Docker (read 2026-11-16)
  4. WonderNetwork: pings from Singapore wondernetwork.com/pings/Singapore — WonderNetwork (read 2026-11-16)

Put the firewall on a Singapore server

Bead in Singapore costs $3.75 a month on 12 months, Linux only.

From $3.75/mo on 12 months · HK · TYO · SIN

Build