VPS指南
[DEMO] A basic firewall with ufw
Close everything you do not use and open only the ports you need with ufw on Ubuntu or Debian.
ufw (Uncomplicated Firewall) is the simplest way to manage the firewall on Ubuntu and Debian.
Install ufw
bashsudo apt update && sudo apt install ufwSet the default policy
bashsudo ufw default deny incoming sudo ufw default allow outgoingAllow SSH
bashsudo ufw allow OpenSSHEnable it and check the status
bashsudo ufw enable sudo ufw status verbose
Common commands
| To… | Command |
|---|---|
| Open a TCP port | sudo ufw allow 25565/tcp |
| Open a range | sudo ufw allow 27015:27030/udp |
| Allow one IP only | sudo ufw allow from [TRUSTED_IP] to any port 3306 |
| Delete a rule | sudo ufw delete allow 25565/tcp |
| Numbered rules | sudo ufw status numbered |
I enabled ufw and locked myself out
Use the panel console or rescue mode [To be confirmed] and run ufw disable. Then start again, allowing SSH first.