# UFW

### General Info

By default, UFW is set to deny all incoming connections and allow all outgoing connections. This means anyone trying to reach your server would not be able to connect, while any application within the server would be able to reach the outside world.

So **make sure to allow ssh before enabling UFW!!!** UFW requires you to add / deny ports in a certain order, if you want to allow a certain ip access a port but deny access by everyone else, the ip must be allowed first then deny all after

<div id="bkmrk-">  
</div>### Setup

```bash
 sudo apt update && sudo apt install -y ufw
```

### Basic Management

Turning UFW on:

```bash
ufw enable
```

Turning UFW off:

```bash
ufw disable
```

Check if UFW is enabled or disabled

```bash
sudo ufw status
```

Allowing access from a particular IP to ANY port

```bash
sudo ufw allow from IP_ADDRESS
```

Allowing access from a partiular IP to A SPECIFIED port:

```bash
 sudo ufw allow from IP_ADDRESS to any port PORT_NUMBER
```

Allowing any access to a specified port:

```bash
 sudo ufw allow PORT_NUMBER
```

Denying access to a specific port

```bash
 sudo ufw deny PORT_NUMBER
```

List rule numbers

```bash
sudo ufw status numbered
```

<div id="bkmrk--1">  
</div>