Tutorials  /  Ubuntu

UFW Essentials: Common Firewall Rules and Commands

Ccentron Redaktion · January 2025 ·4 min read ·Ubuntu, Tutorial

Introductio for UFW Essentials

UFW (uncomplicated firewall) is a firewall configuration tool that runs on top of iptables, included by default within Ubuntu distributions. It provides a streamlined interface for configuring common firewall use cases via the command line.

This cheat sheet-style guide provides a quick reference to common UFW use cases and commands, including examples of how to allow and block services by port, network interface, and source IP address.

VM

Matching infrastructure at centron

Ubuntu servers without your own hardware: ccloud³ VMs with full root access from €3.12 per month, billed by the hour and ready in seconds. Rent a cloud server →

How To Use This Guide for UFW Essentials

  • This guide is in cheat sheet format with self-contained command-line snippets.
  • Jump to any section that is relevant to the task you are trying to complete.
  • Highlighted text in commands should refer to IP addresses from your network.
  • Check your current UFW ruleset with sudo ufw status or sudo ufw status verbose.

Verify UFW Status

To check if UFW is enabled, run:

Code
sudo ufw status

Output:

Code
Status: inactive

Enable UFW

If the firewall is inactive, enable it using:

Code
sudo ufw enable

Output:

Code
Firewall is active and enabled on system startup

Use sudo ufw status verbose to see what is blocked or allowed:

Code
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), deny (routed)
New profiles: skip

Disable UFW

To disable the firewall service, run:

Code
sudo ufw disable

Note: This will fully disable the firewall service on your system.

UFW Essentials: Block an IP Address

To block all network connections from a specific IP address:

Code
sudo ufw deny from 203.0.113.100

Output:

Code
Rule added

Allow an IP Address

To allow all network connections from a specific IP address:

Code
sudo ufw allow from 203.0.113.101

Output:

Code
Rule added

Delete UFW Rule

To delete a rule, use:

Code
sudo ufw delete allow from 203.0.113.101

Alternatively, use rule ID:

Code
sudo ufw delete 1

Allow HTTP and HTTPS Traffic

To allow both HTTP and HTTPS traffic:

Code
sudo ufw allow proto tcp from any to any port 80,443

Output:

Code
Rule added

Conclusion for UFW Essentials

UFW is a powerful tool that enhances server security when configured correctly. It simplifies managing firewall rules efficiently. Use this guide as a quick reference for common firewall rules. With UFW, you can easily allow or block specific ports and IP addresses. Customize your server’s traffic to meet unique needs securely. Proper configuration ensures reliable protection against unauthorized access attempts.

Jetzt 200 € Guthaben sichern

Testen Sie Ihr Setup auf ccloud³

Registrieren Sie sich in der ccloud³ und erhalten Sie 200 € Startguthaben für Ihr Projekt – z. B. für eine PostgreSQL-VM mit automatischen Backups.

centron Redaktion Technische Redaktion

Das Redaktionsteam von centron schreibt Anleitungen aus dem Betriebsalltag: getestet auf unserer eigenen Plattform, betrieben im Rechenzentrum in Hallstadt bei Bamberg.

Kategorie Ubuntu
Teilen
Noch offene Fragen?

Unser Team hilft Ihnen bei Ihrem konkreten Setup weiter – von Menschen, die die Plattform selbst betreiben.

War dieses Tutorial hilfreich?

Ihre Antwort wird anonym gespeichert und hilft uns, die Tutorials zu verbessern.

Kommentare

Noch keine Kommentare – stellen Sie die erste Frage zu diesem Tutorial.

Zum Kommentieren anmelden

Kommentare stehen centron-Kunden offen. Melden Sie sich in Ihrem Konto an, um eine Frage zu diesem Tutorial zu stellen.

Weiterlesen

Das könnte Sie auch interessieren

Jetzt kostenlos anfangen

Melden Sie sich an und erhalten Sie in den ersten 60 Tagen ein Guthaben von 200 € bei centron.

Dieses Werbeangebot gilt nur für neue Konten. Angebot ausschließlich für Gewerbetreibende.

Jetzt loslegen Sales kontaktieren