Here are some common UFW (Uncomplicated Firewall) commands that you can use to manage firewall rules effectively:
Basic Commands
Enable UFW:
sudo ufw enableActivates the firewall with the current rules.
Disable UFW:
sudo ufw disableDeactivates the firewall.
Check Status:
sudo ufw statusDisplays the current status of UFW and the rules in effect.
Verbose Status:
sudo ufw status verboseProvides detailed information about the current rules and policies.
Managing Rules
Allow Incoming Traffic:
sudo ufw allow <port>Example: Allow HTTP traffic on port 80:
sudo ufw allow 80Deny Incoming Traffic:
sudo ufw deny <port>Example: Deny traffic on port 23 (Telnet):
sudo ufw deny 23Allow Specific Service:
sudo ufw allow <service>Example: Allow SSH:
sudo ufw allow sshDelete a Rule:
sudo ufw delete allow <port>Example: Remove the rule allowing HTTP:
sudo ufw delete allow 80
Advanced Commands
Allow Traffic from a Specific IP:
sudo ufw allow from <IP_address>Example: Allow traffic from a specific IP:
sudo ufw allow from 192.168.1.100Deny Traffic from a Specific IP:
sudo ufw deny from <IP_address>Logging:
sudo ufw logging onEnables logging of firewall events.
Reset UFW:
sudo ufw resetResets UFW to its default state, removing all rules.
Example Usage
To set up a basic web server, you might run:
sudo ufw allow ssh
sudo ufw allow 80
sudo ufw enable
This configuration allows SSH access and HTTP traffic while keeping other ports closed.
Feel free to ask if you have any questions or need further clarification on any command!
