> Source: https://docs.cyberelements.io/bastion/4.7/Usage/Reference/ConfigurationFiles/MediationController/ExtraNetFilterRules/

# extraNetFilterRules

`extraNetFilterRules` is where you add your own rules to the local firewall of the Mediation Controller. The product applies a predefined set of rules, then reads this file.

| Property | Value |
|---|---|
| **Component** | Mediation Controller |
| **Path** | `/etc/ipdiva/server/extraNetFilterRules` |
| **Owner and permissions** | `zope:ipdivasrv`, `644` |
| **Package** | `ipdiva-server` (a configuration file kept on upgrade) |
| **Format** | shell script, sourced |

> **The file is only read in cluster mode**
>
> The filtering script of the product does nothing when the server is in **standalone** mode: it returns immediately, before applying any rule and before reading this file. On a Standalone Mediation Controller, writing rules here therefore has **no effect at all**, and nothing says so. The local firewall of a Standalone server is yours to manage, outside the product.

## Structure

The file is **sourced by a shell script**, not parsed as a list of rules: you write commands, one per line, usually `iptables` ones.

```
1
```

It is delivered **empty**.

> **A command here runs as root, and its errors are silent**
>
> Anything a shell accepts is executed, not only `iptables`. A mistyped command fails where the firewall is being built, without stopping it: you end up with a partial rule set. Test your commands before putting them in the file.

## Where your rules take place

The script builds the `INPUT` chain in this order:

1. the default policy of `INPUT` is set to **DROP**;
2. the loopback interface and `127.0.0.0/8` are accepted;
3. TCP 22, TCP 80, the HTTPS port and the SSL Router port are accepted;
4. ICMP is accepted;
5. the addresses of the other node of the cluster, and the virtual addresses, are accepted;
6. **your rules are read here**;
7. finally, the established connections are accepted.

Two consequences:

- your rules are added **after** those of the product, so you cannot remove one of them by writing a rule: an `ACCEPT` placed earlier by the product wins;
- they are added **before** the rule on established connections, which is therefore never shadowed by yours.

> **Rules at shutdown**
>
> The file `/etc/ipdiva/server/stopExtraNetFilterRules`, delivered empty as well, is sourced when the filtering is stopped. Put there what has to be undone, for instance a rule added in another chain.

> **Hardening guide**
>
> See [Local firewall](https://docs.cyberelements.io/bastion/4.7/Security/LocalFirewall/), recommendation R39.

## Applying a change

The filtering script runs when the SSL Router starts, right after it, and `stopExtraNetFilterRules` when it stops: a change only applies when the SSL Router is restarted.

```
1
```

> **Restarting the SSL Router cuts the connections in progress**
>
> The SSL Router carries the connections of the Edge Gateways, of the clients and of the web accesses: those in progress are cut, and during the restart users can neither sign in to the portal nor launch an application. Plan the change outside working hours, and restart one node at a time.

Then check the result:

```
1
```

## Upgrade

The file is kept on upgrade. If you modified it, the upgrade asks whether to keep your version or to install the new one: the version not chosen is kept next to it, as `extraNetFilterRules.dpkg-old` (your former version) or `extraNetFilterRules.dpkg-dist` (the new version).
