UFW should be installed by default in Ubuntu servers. If not, see below.
 
#### Installation of UFW
```ad-command
~~~bash
sudo apt install ufw
~~~
```
 
#### Activation of UFW
```ad-command
~~~bash
sudo ufw status
~~~
```
If disabled:
```ad-command
~~~bash
sudo ufw enable
~~~
```
 
---
 
### Basic commands
[[#^Top|TOP]]
 
#### UFW rules status
```ad-command
~~~bash
sudo ufw status
~~~
```
Commands can be appended:
-`verbose`: details incoming/outgoing rules
-`numbered`: display rule numbers
 
#### UFW rule management
[[#^Top|TOP]]
##### Allow / Deny
```ad-command
~~~bash
sudo ufw allow/deny
~~~
```
Then:
| Type to allow | Syntax
|--------------|--------
**IP** | from (ip address/range)
**Port** | (portnumber)/(protocol)
**Service** | (service name)
**Protocol** | proto (protocol name)
 
##### 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
~~~bash
insert 1 (or any place in the pecking order)
~~~
```
 
##### Complex rule syntax
Finer rules can be defined with the following syntax.
- [ ] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix %%done_del%% 🔁 every week on Saturday 📅 2023-04-15
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix %%done_del%% 🔁 every week on Saturday 📅 2023-04-08 ✅ 2023-04-07
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix %%done_del%% 🔁 every week on Saturday 📅 2023-04-01 ✅ 2023-04-03
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix %%done_del%% 🔁 every week on Saturday 📅 2023-03-25 ✅ 2023-03-25
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix %%done_del%% 🔁 every week on Saturday 📅 2023-03-18 ✅ 2023-03-18
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix %%done_del%% 🔁 every week on Saturday 📅 2023-03-11 ✅ 2023-03-10
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix %%done_del%% 🔁 every week on Saturday 📅 2023-03-04 ✅ 2023-03-03
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix %%done_del%% 🔁 every week on Saturday 📅 2023-02-25 ✅ 2023-02-24
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix %%done_del%% 🔁 every week on Saturday 📅 2023-02-18 ✅ 2023-02-17
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix %%done_del%% 🔁 every week on Saturday 📅 2023-02-11 ✅ 2023-02-11
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix %%done_del%% 🔁 every week on Saturday 📅 2023-02-04 ✅ 2023-02-04