# Firewall

Source: https://openpanel.sh/docs/security/firewall

The ufw rules the setup writes on every connected server, the rules that keep ports Docker publishes closed, the private network's rules, the fail2ban settings, and what a disconnect leaves.

The setup turns on ufw, Ubuntu's firewall, on every server it connects. It replaces any rules the server had.

## The default rules [#the-default-rules]

| Direction | Rule |
|---|---|
| Incoming | Refused by default. |
| Outgoing | Allowed. |
| TCP on the SSH port the setup chose (between 20000 and 60000) | Allowed, labelled `OpenPanel SSH`. |
| TCP 80 | Allowed, labelled `HTTP`. |
| TCP 443 | Allowed, labelled `HTTPS`. |

The SSH port you connected on, usually 22, is closed once SSH has moved to its new port.

## Ports Docker publishes [#ports-docker-publishes]

Docker writes its own forwarding rules, which pass before ufw's, so a port a container publishes would otherwise be open to the internet whatever ufw says. The setup adds rules to Docker's `DOCKER-USER` chain, in ufw's own files (`/etc/ufw/after.rules` and `after6.rules`), for IPv4 and IPv6:

| Traffic | Rule |
|---|---|
| Answers to connections a container made | Allowed |
| From Docker's own networks, and from the private network's interface | Allowed |
| To a published port 80 or 443, from outside | Allowed |
| Anything else to a container, from outside | Dropped |

The setup checks that Docker's forwarding passes through these rules, and stops if it does not. OpenPanel's own services publish no ports: their traffic reaches them through the [agent](/docs/servers/agent).

## The private network [#the-private-network]

When the server joins the organization's [private network](/docs/network), the setup adds two rules, both labelled `OpenPanel private network`:

| Rule | Why |
|---|---|
| Everything arriving on the network's interface, `quietlane0` | So your organization's devices and servers reach the server on every port of its private address. |
| UDP 41641 | So other devices can connect to the server directly instead of through a relay. |

## fail2ban [#fail2ban]

fail2ban watches SSH on its new port. An address with 5 failed sign-ins within 10 minutes is banned for an hour.

## See the rules on a server [#see-the-rules-on-a-server]

A server's page shows its firewall under **Security**, from a live reading. On the server itself, `sudo ufw status verbose` lists the rules.

## Ports for your services [#ports-for-your-services]

Your services need no port on the server's firewall. Their HTTP, TCP and UDP traffic arrives at OpenPanel's edge and reaches them through the agent's own outgoing connection, so the server opens nothing for them. See the [Ports reference](/docs/tcp-udp/ports) for every port OpenPanel uses.

## After a disconnect [#after-a-disconnect]

A clean disconnect removes the two private-network rules. The other rules stay, with SSH still on its new port, and so do the rules for Docker's ports: they only protect the server. See [Disconnect and force disconnect](/docs/servers/disconnect).