ข้ามไปยังเนื้อหา
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.

  1. Install ufw

    bash
    sudo apt update && sudo apt install ufw
  2. Set the default policy

    bash
    sudo ufw default deny incoming
    sudo ufw default allow outgoing
  3. Allow SSH

    bash
    sudo ufw allow OpenSSH
  4. Enable it and check the status

    bash
    sudo ufw enable
    sudo ufw status verbose

Common commands

To…Command
Open a TCP portsudo ufw allow 25565/tcp
Open a rangesudo ufw allow 27015:27030/udp
Allow one IP onlysudo ufw allow from [TRUSTED_IP] to any port 3306
Delete a rulesudo ufw delete allow 25565/tcp
Numbered rulessudo 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.