Report issue Add example

ufw

Ubuntu firewall management tool

Synopsis

sudo ufw [options] [rule/command]

Purpose

Parameters

Common Operation Commands

Rule Formats

Options


Return Value


Examples

Basic Operations

# Enable firewall
sudo ufw enable

# Disable firewall
sudo ufw disable

# View firewall status
sudo ufw status

Rule Configuration

# Allow default SSH port (22/tcp)
sudo ufw allow ssh

# Allow port 8080 for TCP and add a comment
sudo ufw allow 8080/tcp comment "Web Server"

# Deny access from 192.168.1.5
sudo ufw deny from 192.168.1.5

# Deny port 53 for UDP
sudo ufw deny 53/udp

Advanced Operations

# Show numbered rule list (useful for deletion)
sudo ufw status numbered

# Delete the 3rd rule
sudo ufw delete 3

# Reset all rules
sudo ufw reset

Notes

  1. Privilege Requirement: Commands must be executed using sudo.
  2. Default Policy: When first enabled, it defaults to blocking all incoming traffic and allowing all outgoing traffic.
  3. Rule Priority: Rules are matched in order; denying before allowing may cause conflicts.
  4. Logging: Enable logging with sudo ufw logging on; logs are located at /var/log/ufw.log.
  5. Service Name Support: Supports service names defined in /etc/services (e.g., http, ssh).