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.
156 lines
2.0 KiB
156 lines
2.0 KiB
3 years ago
|
---
|
||
|
|
||
|
Alias: ["UFW"]
|
||
|
Tag: ["Server", "Firewall"]
|
||
|
Date: 2021-10-04
|
||
|
DocType: "Personal"
|
||
|
Hierarchy: "NonRoot"
|
||
|
TimeStamp:
|
||
|
location: [51.514678599999996, -0.18378583926867909]
|
||
|
CollapseMetaTable: Yes
|
||
|
|
||
|
---
|
||
|
|
||
3 years ago
|
Parent:: [[Selfhosting]], [[Server Alias]], [[Server Cloud]], [[Server Tools]], [[Server VPN]]
|
||
3 years ago
|
|
||
|
---
|
||
|
|
||
|
 
|
||
|
|
||
|
```button
|
||
|
name Save
|
||
|
type command
|
||
|
action Save current file
|
||
|
id Save
|
||
|
```
|
||
|
^button-UFWSave
|
||
|
|
||
|
 
|
||
|
|
||
3 years ago
|
# Configuring UFW
|
||
3 years ago
|
|
||
|
 
|
||
|
|
||
|
```ad-abstract
|
||
|
title: Summary
|
||
|
collapse: open
|
||
|
Description of basic commands for UFW
|
||
|
```
|
||
|
|
||
|
 
|
||
|
|
||
|
```toc
|
||
|
style: number
|
||
|
```
|
||
|
|
||
|
 
|
||
|
|
||
|
---
|
||
|
|
||
|
 
|
||
|
|
||
|
### Installation and activation
|
||
|
|
||
|
 
|
||
|
|
||
|
UFW should be installed by default in Ubuntu servers. If not, see below.
|
||
|
|
||
|
 
|
||
|
|
||
|
#### Installation of UFW
|
||
|
|
||
3 years ago
|
```ad-command
|
||
|
~~~
|
||
|
sudo apt install ufw
|
||
|
~~~
|
||
|
```
|
||
3 years ago
|
|
||
|
 
|
||
|
|
||
|
#### Activation of UFW
|
||
|
|
||
3 years ago
|
```ad-command
|
||
|
~~~
|
||
|
sudo ufw status
|
||
|
~~~
|
||
|
```
|
||
3 years ago
|
|
||
|
If disabled:
|
||
|
|
||
3 years ago
|
```ad-command
|
||
|
~~~
|
||
|
sudo ufw enable
|
||
|
~~~
|
||
|
```
|
||
3 years ago
|
|
||
|
 
|
||
|
|
||
|
---
|
||
|
|
||
|
 
|
||
|
|
||
|
### Basic commands
|
||
|
|
||
|
 
|
||
|
|
||
|
#### UFW rules status
|
||
|
|
||
3 years ago
|
```ad-command
|
||
|
~~~
|
||
|
sudo ufw status
|
||
|
~~~
|
||
|
```
|
||
3 years ago
|
|
||
|
Commands can be appended:
|
||
|
- `verbose`: details incoming/outgoing rules
|
||
|
- `numbered`: display rule numbers
|
||
|
|
||
|
 
|
||
|
|
||
|
#### UFW rule management
|
||
|
|
||
|
##### Allow / Deny
|
||
|
|
||
3 years ago
|
```ad-command
|
||
|
~~~
|
||
|
sudo ufw allow/deny
|
||
|
~~~
|
||
|
```
|
||
3 years ago
|
|
||
|
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:
|
||
|
|
||
3 years ago
|
```ad-command
|
||
|
~~~
|
||
|
insert 1 (or any place in the pecking order)
|
||
|
~~~
|
||
|
```
|
||
3 years ago
|
|
||
|
 
|
||
|
|
||
|
##### 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
|
||
|
|
||
|
 
|
||
|
 
|