Linux Terminal Command: ufw
The ufw command is an essential tool in Network Utilities. In this tutorial, we will explore what ufw does, look at everyday examples, and cover advanced options to supercharge your command-line workflow.
Concept & Explanation
The ufw command is a user-friendly frontend command for managing iptables firewalls on Debian and Ubuntu systems.
Common Options & Syntax
ufw [options] [arguments]
Here are the most common flags used with ufw:
- Simple Usage: Basic default commands.
- Detailed View: Shows diagnostic information.
- Advanced Actions: Can chain parameters for scripting.
1. Interactive Example (Simple)
Here is how most people run the command:
# Example
sudo ufw status
What it does: Shows the active firewall configuration status.
2. Power-User Example (Advanced)
For scripting and advanced diagnostics, use this configuration:
# Advanced
sudo ufw default deny incoming && sudo ufw allow 22/tcp && sudo ufw allow 80,443/tcp && sudo ufw enable
What it does: Blocks all incoming connections, allows SSH on port 22, allows web services, and activates the firewall.
⚙️ Warning & Common Pitfalls
[!WARNING] Always run
sudo ufw allow 22/tcp(or your custom SSH port) before runningsudo ufw enable, otherwise you will lock yourself out of the remote server.
🔗 Related Commands
Here are some related posts on cli_tty1 you might want to check out: