Skip to content

Latest commit

 

History

History
86 lines (61 loc) · 1.77 KB

ufw-basic-setup.md

File metadata and controls

86 lines (61 loc) · 1.77 KB

Basic UFW (Uncomplicated Firewall) setup

This guide covers essential UFW commands and best practices for securing your server.


1. Viewing UFW rules

  • Show all active rules (with details):

    sudo ufw status verbose
  • Show rules with numbering (for easy deletion):

    sudo ufw status numbered

2. Managing rules

  • Delete a specific rule by its number:
    sudo ufw delete <RULE_NUMBER>
    Replace <RULE_NUMBER> with the number shown in ufw status numbered.

3. Allowing common services

  • Allow SSH (port 22) from anywhere:

    sudo ufw allow proto tcp to any port 22

    Tip: For better security, consider restricting SSH to your IP if possible.

  • Allow HTTP (port 80):

    sudo ufw allow proto tcp to any port 80
  • Allow HTTPS (port 443):

    sudo ufw allow proto tcp to any port 443

4. Setting default policies

  • Deny all incoming connections by default:

    sudo ufw default deny incoming
  • Allow all outgoing connections by default:

    sudo ufw default allow outgoing

5. Enabling UFW

  • Enable the firewall (after setting your rules):
    sudo ufw enable

6. Security notes

  • By default, allowing SSH from anywhere is convenient, but less secure.
    If your IP is static, restrict SSH access to your IP:
    sudo ufw allow from <YOUR.IP.ADDRESS> to any port 22 proto tcp
  • If your IP changes frequently, consider using Fail2ban to protect SSH by blocking repeated failed login attempts.

Remember:
Always double-check your rules before enabling UFW, especially if you are connected via SSH, to avoid locking yourself out.