Canonical: https://nitride.xyz/docs/delivery/firewall

# Firewall rules for the feed

Two firewall states: open while we verify your destination, then, if you want, narrowed to the address the stream comes from.

## Why two states?
The verification datagram and the shreds both come from our server, but support gives you the numeric source address only once delivery is active. So the rule you need changes once:

| Stage | What the port must accept |
| --- | --- |
| Verification, for a paid plan or a trial | UDP from any address |
| Delivery active, default | UDP from any address (still works) |
| Delivery active, narrowed | UDP from the source address support gives you |

Narrowing is optional but worth doing: an open UDP port receives whatever anyone sends it. Once delivery is active, support can give you the address we send from; we do not publish it.

Every example below uses UDP port `9000`. Each layer that filters traffic needs the rule: the host firewall and any cloud firewall in front of it.

## ufw
Open the port:

```sh
sudo ufw allow 9000/udp
```

Narrow it later, adding the specific rule before removing the general one so there is no gap:

```sh
sudo ufw allow proto udp from <source-ip> to any port 9000
sudo ufw delete allow 9000/udp
sudo ufw status numbered
```

## nftables
These assume an `inet filter` table with an `input` chain, the layout most distributions ship. `insert` places a rule at the top of the chain, ahead of any final drop rule that `add` would land behind. Open:

```sh
sudo nft insert rule inet filter input udp dport 9000 accept
```

Narrow: add the specific rule, then delete the open one by its handle.

```sh
sudo nft insert rule inet filter input ip saddr <source-ip> udp dport 9000 accept
sudo nft -a list chain inet filter input
sudo nft delete rule inet filter input handle <handle>
```

Save the ruleset to the file your distribution loads at boot, often `/etc/nftables.conf`, or the rules disappear on restart.

## iptables
On hosts still managed with iptables:

```sh
sudo iptables -I INPUT -p udp --dport 9000 -j ACCEPT
```

Narrowed:

```sh
sudo iptables -I INPUT -p udp -s <source-ip> --dport 9000 -j ACCEPT
sudo iptables -D INPUT -p udp --dport 9000 -j ACCEPT
```

`-I` puts the rule at the top of the chain, ahead of any broad reject rules. Persist with your distribution's tool, for example `iptables-save` into the file `netfilter-persistent` reads.

## firewalld
```sh
sudo firewall-cmd --permanent --add-port=9000/udp
sudo firewall-cmd --reload
```

To narrow, replace the open port with a rich rule for the source address:

```sh
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="<source-ip>" port port="9000" protocol="udp" accept'
sudo firewall-cmd --permanent --remove-port=9000/udp
sudo firewall-cmd --reload
```

## Cloud firewalls and security groups
Cloud providers filter traffic before it reaches your server, and their defaults usually block inbound UDP. Add an inbound rule with:

- protocol **UDP**;
- port **9000** (a single port, not a range);
- source **any IPv4 address** (`0.0.0.0/0`) while verifying, then `<source-ip>/32` once narrowed.

The console wording differs between providers, but those three fields are always there. If the server sits behind a separate network firewall or a NAT gateway, it needs the same rule and a port forward; see [your destination IP and port](https://nitride.xyz/docs/delivery/destination).

## Does connection tracking get in the way?
Usually not. Stateful firewalls track UDP "connections" by address and port pairs, and a rule like the ones above accepts the first packet of each new flow. Two things to avoid: a policy that only accepts `ESTABLISHED` traffic, which never lets the first datagram in, and a rate limit on new UDP flows, which can drop the burst at the start of delivery.

## How do I know the rule works?
Run tcpdump on the server while the verification datagram or the stream is due:

```sh
sudo tcpdump -n -i any -c 10 'udp dst port 9000'
```

If tcpdump shows packets but your receiver does not, the firewall is fine and the problem is the socket; the [command-line checks](https://nitride.xyz/docs/cli) cover that case. If tcpdump shows nothing, check each filtering layer in turn, starting with the cloud one, and then [troubleshooting](https://nitride.xyz/docs/troubleshooting). Back to the [docs overview](https://nitride.xyz/docs).
