> ## Documentation Index
> Fetch the complete documentation index at: https://docs.ahmadraza.in/llms.txt
> Use this file to discover all available pages before exploring further.

# Ufw firewall

# UFW (Uncomplicated Firewall) Command Reference

## Basic UFW Operations

* **Enable the Firewall**
  ```bash theme={null}
  sudo ufw enable
  ```

* **Disable the Firewall**
  ```bash theme={null}
  sudo ufw disable
  ```

* **Check Firewall Status**
  ```bash theme={null}
  sudo ufw status
  ```

## Allowing Traffic

* **Allow Incoming Traffic on a Specific Port (e.g., SSH)**
  ```bash theme={null}
  sudo ufw allow <port_number>/tcp
  ```

* **Allow Incoming Traffic on a Specific Port and Protocol (e.g., UDP)**
  ```bash theme={null}
  sudo ufw allow <port_number>/udp
  ```

* **Allow Incoming Traffic from a Specific IP Address**
  ```bash theme={null}
  sudo ufw allow from <ip_address>
  ```

* **Allow Incoming Traffic from a Specific IP Address and Port**
  ```bash theme={null}
  sudo ufw allow from <ip_address> to any port <port_number>
  ```

* **Allow Incoming Traffic from a Specific IP Range**
  ```bash theme={null}
  sudo ufw allow from <ip_range>
  ```

* **Allow Outgoing Traffic on a Specific Port (e.g., HTTP)**
  ```bash theme={null}
  sudo ufw allow out <port_number>/tcp
  ```

* **Allow a Specific Application/Service (e.g., Apache Full)**
  ```bash theme={null}
  sudo ufw allow 'Apache Full'
  ```

## Denying Traffic

* **Deny Incoming Traffic on a Specific Port (e.g., FTP)**
  ```bash theme={null}
  sudo ufw deny <port_number>/tcp
  ```

* **Deny Incoming Traffic from a Specific IP Address**
  ```bash theme={null}
  sudo ufw deny from <ip_address>
  ```

* **Limit the Rate of Incoming Connections (e.g., SSH)**
  ```bash theme={null}
  sudo ufw limit <port_number>/tcp
  ```

## Managing Rules

* **Delete a Specific Rule by Its Rule Number**
  ```bash theme={null}
  sudo ufw delete <rule_number>
  ```

* **Reset UFW to Default Settings**
  ```bash theme={null}
  sudo ufw reset
  ```

* **Show Advanced UFW Options**
  ```bash theme={null}
  sudo ufw --help
  ```

* **Show the List of Applications/Services That Can Be Enabled**
  ```bash theme={null}
  sudo ufw app list
  ```

* **Enable a Specific Application/Service (e.g., OpenSSH)**
  ```bash theme={null}
  sudo ufw allow OpenSSH
  ```

* **Disable a Specific Application/Service (e.g., OpenSSH)**
  ```bash theme={null}
  sudo ufw delete allow OpenSSH
  ```

* **Enable Logging of UFW Actions**
  ```bash theme={null}
  sudo ufw logging on
  ```

* **Disable Logging of UFW Actions**
  ```bash theme={null}
  sudo ufw logging off
  ```

* **Reset UFW to Factory Defaults (Disable and Delete All Rules)**
  ```bash theme={null}
  sudo ufw --force reset
  ```

## Example Commands for Apache and Nginx

* **Allow Apache Traffic**
  ```bash theme={null}
  sudo ufw allow 'Apache Full'
  sudo ufw delete allow 'Apache'
  ```

* **Allow Nginx Traffic**
  ```bash theme={null}
  sudo ufw allow 'Nginx Full'
  sudo ufw delete allow 'Nginx HTTP'
  ```

* **Allow Specific Port (e.g., SSH)**
  ```bash theme={null}
  sudo ufw allow 22/tcp
  ```

* **Deny Specific Port (e.g., HTTP)**
  ```bash theme={null}
  sudo ufw deny 80/tcp
  ```

## `iptables` Command Reference

### Basic `iptables` Operations

* **List All Rules**
  ```bash theme={null}
  sudo iptables -L
  ```

* **Flush (Reset) All Rules**
  ```bash theme={null}
  sudo iptables -F
  ```

### Managing Rules

* **Allow Incoming SSH Connections (Port 22)**
  ```bash theme={null}
  sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
  ```

* **Allow Incoming Connections from a Specific IP Address**
  ```bash theme={null}
  sudo iptables -A INPUT -p tcp -s 192.168.1.100 -j ACCEPT
  ```

* **Deny Incoming Connections from a Specific IP Address**
  ```bash theme={null}
  sudo iptables -A INPUT -p tcp -s 192.168.1.200 -j DROP
  ```

* **Delete a Specific Rule by Its Line Number**
  ```bash theme={null}
  sudo iptables -D INPUT [line number]
  ```

***

> This docs provides a quick reference for managing firewall rules with UFW and `iptables`. Make sure to adjust the port numbers, IP addresses, and service names according to your specific requirements.
