Tutorials  /  Ubuntu

UFW Essentials: Common Firewall Rules and Commands

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

Contents

  1. Introductio for UFW Essentials
  2. How To Use This Guide for UFW Essentials
  3. Verify UFW Status
  4. Enable UFW
  5. Disable UFW
  6. UFW Essentials: Block an IP Address
  7. Allow an IP Address
  8. Delete UFW Rule
  9. Allow HTTP and HTTPS Traffic
  10. Conclusion for UFW Essentials

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.

SEC

Want your firewall rules managed?

centron's Managed Firewall takes care of rule sets, updates and 24/7 monitoring, from €57.58 per month. View Managed Firewall →

Prefer self-service? Cloud Firewall from €7.58 per month →

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.

Claim €200 credit

Test your setup on ccloud³

Sign up for ccloud³ and receive €200 starting credit for your project.

centron Redaktion Technical editorial team

The centron editorial team writes guides from day-to-day operations: tested on our own platform, run in our data centre in Hallstadt near Bamberg.

Category Ubuntu
Share
Still have questions?

Our team will help you with your specific setup - in German or English, by people who run the platform themselves.

Was this tutorial helpful?

Your answer is stored anonymously and helps us improve our tutorials.

Comments

No comments yet - be the first to ask a question about this tutorial.

Sign in to comment

Comments are open to centron customers. Sign in to your account to ask a question about this tutorial.

Get started for free

Sign up and receive €200 credit at centron within your first 60 days.

This promotional offer applies to new accounts only. Available exclusively to businesses.