You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
311 lines
13 KiB
311 lines
13 KiB
---
|
|
|
|
Alias: ["UFW"]
|
|
Tag: ["🖥️", "Firewall"]
|
|
Date: 2021-10-04
|
|
DocType: "Personal"
|
|
Hierarchy: "NonRoot"
|
|
TimeStamp:
|
|
location: [51.514678599999996, -0.18378583926867909]
|
|
CollapseMetaTable: true
|
|
|
|
---
|
|
|
|
Parent:: [[Selfhosting]], [[Server Alias]], [[Server Cloud]], [[Server Tools]], [[Server VPN]]
|
|
|
|
---
|
|
|
|
^Top
|
|
|
|
 
|
|
|
|
```button
|
|
name Save
|
|
type command
|
|
action Save current file
|
|
id Save
|
|
```
|
|
^button-UFWSave
|
|
|
|
 
|
|
|
|
# Configuring UFW
|
|
|
|
 
|
|
|
|
```ad-abstract
|
|
title: Summary
|
|
collapse: open
|
|
Description of basic commands for UFW
|
|
```
|
|
|
|
 
|
|
|
|
```toc
|
|
style: number
|
|
```
|
|
|
|
 
|
|
|
|
---
|
|
|
|
 
|
|
|
|
### Installation and activation
|
|
[[#^Top|TOP]]
|
|
 
|
|
|
|
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.
|
|
|
|
| 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
|
|
|
|
 
|
|
|
|
##### Delete a rule
|
|
|
|
```ad-command
|
|
~~~bash
|
|
sudo ufw delete <rule number>
|
|
~~~
|
|
```
|
|
|
|
 
|
|
|
|
---
|
|
|
|
 
|
|
|
|
### Ban List management
|
|
[[#^Top|TOP]]
|
|
 
|
|
|
|
#### Ban List Folder
|
|
|
|
```ad-path
|
|
/etc/addip4ban/
|
|
```
|
|
|
|
 
|
|
|
|
#### Ban List Script
|
|
|
|
```ad-code
|
|
title: addip4ban.sh
|
|
~~~bash
|
|
#!/bin/bash
|
|
|
|
INPUT="/etc/addip4ban/blocked.ip.list"
|
|
|
|
while IFS= read -r block
|
|
do
|
|
sudo ufw insert 1 deny from "$block"
|
|
done < "$INPUT"
|
|
~~~
|
|
```
|
|
|
|
 
|
|
|
|
Once written, the script needs to be executed. To prepare:
|
|
|
|
```ad-command
|
|
~~~bash
|
|
sudo chmod +x /etc/addip4ban/addip4ban.sh
|
|
~~~
|
|
```
|
|
|
|
 
|
|
|
|
#### Ban List Document
|
|
|
|
```ad-code
|
|
title: blocked.ip.list
|
|
~~~bash
|
|
< ip1 >
|
|
< ip2/range >
|
|
< ip3 >
|
|
~~~
|
|
```
|
|
|
|
 
|
|
|
|
#### Ban list Update Process
|
|
|
|
Copy/paste the new ban list into `blocked.ip.list` and run:
|
|
|
|
```ad-command
|
|
~~~bash
|
|
sudo bash /etc/addip4ban/addip4ban.sh
|
|
~~~
|
|
```
|
|
|
|
 
|
|
|
|
#### Ban List Tasks
|
|
|
|
- [ ] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix %%done_del%% 🔁 every week on Saturday 📅 2022-10-15
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix %%done_del%% 🔁 every week on Saturday 📅 2022-10-08 ✅ 2022-10-09
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix %%done_del%% 🔁 every week on Saturday 📅 2022-10-02 ✅ 2022-10-01
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix %%done_del%% 🔁 every week on Saturday 📅 2022-10-01 ✅ 2022-10-01
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix %%done_del%% 🔁 every week on Saturday 📅 2022-09-24 ✅ 2022-09-23
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix %%done_del%% 🔁 every week on Saturday 📅 2022-09-17 ✅ 2022-09-16
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix %%done_del%% 🔁 every week on Saturday 📅 2022-09-10 ✅ 2022-09-10
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix %%done_del%% 🔁 every week on Saturday 📅 2022-09-03 ✅ 2022-09-02
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix %%done_del%% 🔁 every week on Saturday 📅 2022-08-27 ✅ 2022-08-26
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix %%done_del%% 🔁 every week on Saturday 📅 2022-08-20 ✅ 2022-08-19
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix %%done_del%% 🔁 every week on Saturday 📅 2022-08-13 ✅ 2022-08-12
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-08-06 ✅ 2022-08-05
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-07-30 ✅ 2022-07-29
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-07-23 ✅ 2022-07-22
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-07-16 ✅ 2022-07-15
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-07-09 ✅ 2022-07-08
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-07-02 ✅ 2022-07-03
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-06-25 ✅ 2022-06-24
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-06-18 ✅ 2022-06-20
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-06-11 ✅ 2022-06-14
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-06-04 ✅ 2022-06-04
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-05-28 ✅ 2022-05-28
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-05-21 ✅ 2022-05-21
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-05-14 ✅ 2022-05-14
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-05-07 ✅ 2022-05-06
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-04-30 ✅ 2022-05-01
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-04-23 ✅ 2022-04-22
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-04-16 ✅ 2022-04-16
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-04-10 ✅ 2022-04-10
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-04-02 ✅ 2022-04-02
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-03-26 ✅ 2022-03-26
|
|
- [x] :desktop_computer: [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-10-22 ✅ 2022-03-18
|
|
- [x] :desktop_computer: [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-10-15 ✅ 2022-10-07
|
|
- [x] :desktop_computer: [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-10-08 ✅ 2022-10-07
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-10-02 ✅ 2022-10-01
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]] Get IP addresses caught by Postfix 🔁 every week on Saturday 📅 2022-10-01 ✅ 2022-10-01
|
|
- [ ] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-10-15
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-10-08 ✅ 2022-10-09
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-10-01 ✅ 2022-10-01
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-09-24 ✅ 2022-09-23
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-09-17 ✅ 2022-09-16
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-09-10 ✅ 2022-09-10
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-09-03 ✅ 2022-09-02
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-08-27 ✅ 2022-08-26
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-08-20 ✅ 2022-08-19
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-08-13 ✅ 2022-08-12
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-08-06 ✅ 2022-08-05
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-07-30 ✅ 2022-07-29
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-07-23 ✅ 2022-07-22
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-07-16 ✅ 2022-07-15
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-07-09 ✅ 2022-07-08
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-07-02 ✅ 2022-07-03
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-06-25 ✅ 2022-06-24
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-06-18 ✅ 2022-06-20
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-06-11 ✅ 2022-06-14
|
|
- [x] 🖥 [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-06-04 ✅ 2022-06-04
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-05-28 ✅ 2022-05-28
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-05-21 ✅ 2022-05-21
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-05-14 ✅ 2022-05-14
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-05-07 ✅ 2022-05-06
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-04-30 ✅ 2022-05-01
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-04-23 ✅ 2022-04-22
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-04-16 ✅ 2022-04-16
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-04-10 ✅ 2022-04-10
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-04-02 ✅ 2022-04-02
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-03-26 ✅ 2022-03-26
|
|
- [x] [[Selfhosting]], [[Configuring UFW|Firewall]]: Update the Blocked IP list 🔁 every month on Saturday 📅 2022-03-19 ✅ 2022-03-18
|
|
|
|
[[#^Top|TOP]]
|
|
|
|
 
|
|
  |