---

Alias: ["UFW"]
Tag: ["Server", "Firewall"]
Date: 2021-10-04
DocType: "Personal"
Hierarchy: "NonRoot"
TimeStamp:
location: [51.514678599999996, -0.18378583926867909]
CollapseMetaTable: Yes

---

Parent:: [[Selfhosting]], [[Server Alias]], [[Server Cloud]], [[Server Tools]]

---

&emsp;

```button
name Save
type command
action Save current file
id Save
```
^button-UFWSave

&emsp;

# Configuring UFW

&emsp;

```ad-abstract
title: Summary
collapse: open
Description of basic commands for UFW
```

&emsp;

```toc
style: number
```

&emsp;

---

&emsp;

### Installation and activation

&emsp;

UFW should be installed by default in Ubuntu servers. If not, see below.

&emsp;

#### Installation of UFW

```ad-command
~~~
sudo apt install ufw
~~~
```

&emsp;

#### Activation of UFW

```ad-command
~~~
sudo ufw status
~~~
```

If disabled:

```ad-command
~~~
sudo ufw enable
~~~
```

&emsp;

---

&emsp;

### Basic commands

&emsp;

#### UFW rules status

```ad-command
~~~
sudo ufw status
~~~
```

Commands can be appended:
- `verbose`: details incoming/outgoing rules
- `numbered`: display rule numbers

&emsp;

#### UFW rule management

##### Allow / Deny

```ad-command
~~~
sudo ufw allow/deny
~~~
```

Then:

| Type to allow | Syntax
|--------------|--------
**IP** | from (ip address/range)
**Port** | (portnumber)/(protocol)
**Service** | (service name)
**Protocol** | proto (protocol name)

&emsp;

##### Rule priority

Certain rules like IP denial need to be put on top of the rule stack as UFW reads rules in order one after another. Insert the following in the command to force insertion:

```ad-command
~~~
insert 1 (or any place in the pecking order)
~~~
```

&emsp;

##### Complex rule syntax

Finer rules can be defined with the following syntax.

| rule condition | syntax
|--------------|--------
**connecting IP** | from (ip or any)
**internal IP** | to (ip or any)
**protocol** | proto (protocol or any)
**port** | port (port or any)
**outgoing traffic** | out

&emsp;
&emsp;