VPS one-click scripts
All scripts / Tutorials / firewall

VPS Firewall Tutorial (UFW / firewalld, SSH Allowed First)

This tutorial shows how to apply a basic host firewall with xyz.sh/firewall (alias ufw). Confirm the detected SSH port before enabling it, or you may lose access.

Command
$ curl -fsSL xyz.sh/firewall | bash

Details · xyz.sh/firewall · Last updated:

What it does

Debian/Ubuntu use UFW; CentOS/Rocky/AlmaLinux use firewalld. The SSH port is detected from sshd_config (or default 22, or the current SSH session) and allowed first, then 80/443 or any --allow ports. Incoming traffic is denied by default; outgoing is allowed.

Warning: the UFW path runs ufw --force reset, which clears existing UFW rules before applying this policy.

Commands

Default policy: curl -fsSL xyz.sh/firewall | bash

SSH only: curl -fsSL xyz.sh/firewall | bash -s -- --ssh-only

Extra port: bash -s -- --allow 8443 Inspect: --status Disable: --disable

The alias curl -fsSL xyz.sh/ufw | bash runs the same script.