Gonka host protection guide (DDoS)
This guide helps hosts protect their nodes against DDoS attacks. It covers the recommended baseline, three ways to put protection in front of the node, how to check that it works, and what to do during an attack.
Baseline protection
Recommended for every host. Setup takes about 15 minutes and does not change how the network reaches your node.
- Firewall. In your provider's firewall, open ports 5000 and 8000 to everyone, 9100 only to your own ML nodes, and 22 only to your own IPs. Close the rest. Use the provider's firewall: host firewalls such as UFW do not apply to ports published by Docker. If you changed the default ports, use your own.
-
Limit new connections per address. Run on the node, and save the rule so it survives a reboot (for example with iptables-persistent):
iptables -t mangle -A PREROUTING -p tcp --syn -m multiport --dports 8000,5000 -m hashlimit --hashlimit-above 50/sec --hashlimit-burst 100 --hashlimit-mode srcip --hashlimit-name gonka-syn -j DROP -
SSH. Allow keys only: set
PasswordAuthentication noin/etc/ssh/sshd_config. Keep your current session open until a new login works. - Ask your provider what DDoS protection is included in your plan and at what traffic level they blackhole your IP.
Put protection in front of the node
The baseline covers the common cases. For large network-level floods, add one of these options. Options A and B are the main routes; Option C applies mainly to hosts that already use Cloudflare Enterprise.
| Option | Fits when | Effort | Cost |
|---|---|---|---|
| A. Move the network node to a protected provider | The network node runs apart from the GPU machines | Low | A server at the new provider |
| B. Protected VPS in front, tunnel to the node | The node cannot move, or everything runs on one machine | Medium | A small VPS |
| C. Cloudflare Spectrum | You already have a Cloudflare Enterprise contract | Low | High, by quote |
Rules for every option
-
Update your address on chain. After you change
config.env, send this transaction from your account (cold) key. It changes only the address:inferenced tx inference submit-new-participant http://NEW_ADDRESS:8000 \ --from <account key> --keyring-backend file \ --chain-id gonka-mainnet --node <rpc url> -
Switch in this order: set
PUBLIC_URLandP2P_EXTERNAL_ADDRESSinconfig.env, recreate theapiandnodecontainers, then send the transaction. Do it right after a PoC ends, not before one. - Keep the old address working until one full PoC has passed on the new one. Rollback is the same transaction with the old address.
- Put the protection close to the node. Added latency reduces how often your node wins inference requests and can delay session finalization. Use the same city or region.
Option A: move the network node to a provider with DDoS protection
The simpler option. It fits if your network node (chain node, API, proxy) runs on a different machine from your GPU ML nodes.
- Pick a provider whose protection is always on and covers every TCP port, not only web ports.
- Move the network node there and switch the address as described above.
- Keep the link to your ML nodes private: a private network or a WireGuard tunnel between your own machines.
Option B: a protected VPS in front, with a tunnel to the node
A small VPS with DDoS protection receives traffic on ports 8000 and 5000 and passes it to your node through a WireGuard tunnel. Connections that arrive through the tunnel are answered through the tunnel. Everything else on the node, including SSH, stays as it was. This works for a node with its own public IP and for a node behind NAT.
Install WireGuard on both machines (apt install wireguard-tools) and create a key pair on each. Below, F_IP is the VPS's public IP and eth0 is its public interface.
1. On the VPS, create /etc/wireguard/wg0.conf:
[Interface]
Address = 10.9.0.1/24
MTU = 1280
ListenPort = 51820
PrivateKey = <VPS private key>
PostUp = sysctl -w net.ipv4.ip_forward=1
PostUp = iptables -t mangle -A PREROUTING -i eth0 -p tcp --syn -m multiport --dports 8000,5000 -m hashlimit --hashlimit-above 50/sec --hashlimit-burst 100 --hashlimit-mode srcip --hashlimit-name gonka-syn -j DROP
PostUp = iptables -t nat -A PREROUTING -i eth0 -p tcp -m multiport --dports 8000,5000 -j DNAT --to-destination 10.9.0.2
PostUp = iptables -t mangle -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
PostDown = iptables -t mangle -D PREROUTING -i eth0 -p tcp --syn -m multiport --dports 8000,5000 -m hashlimit --hashlimit-above 50/sec --hashlimit-burst 100 --hashlimit-mode srcip --hashlimit-name gonka-syn -j DROP
PostDown = iptables -t nat -D PREROUTING -i eth0 -p tcp -m multiport --dports 8000,5000 -j DNAT --to-destination 10.9.0.2
PostDown = iptables -t mangle -D FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
[Peer]
PublicKey = <node public key>
AllowedIPs = 10.9.0.2/32
The hashlimit rule drops new connections from any single address above 50 per second, so a flood from one source is not passed on to your node. Clients that share one public IP count as one address.
2. On the node, create /etc/wireguard/wg0.conf:
[Interface]
Address = 10.9.0.2/24
MTU = 1280
Table = off
PrivateKey = <node private key>
PostUp = ip route add default dev wg0 table 100
PostUp = ip rule add fwmark 0x64 lookup 100 priority 100
PostUp = iptables -t mangle -A PREROUTING -i wg0 -m conntrack --ctstate NEW -j CONNMARK --set-mark 0x64
PostUp = iptables -t mangle -A PREROUTING ! -i wg0 -m connmark --mark 0x64 -j CONNMARK --restore-mark
PostDown = ip rule del fwmark 0x64 lookup 100 priority 100
PostDown = iptables -t mangle -D PREROUTING -i wg0 -m conntrack --ctstate NEW -j CONNMARK --set-mark 0x64
PostDown = iptables -t mangle -D PREROUTING ! -i wg0 -m connmark --mark 0x64 -j CONNMARK --restore-mark
[Peer]
PublicKey = <VPS public key>
Endpoint = F_IP:51820
AllowedIPs = 0.0.0.0/0
PersistentKeepalive = 25
Table = off keeps the node's own routes unchanged, so SSH is not affected.
3. Start the tunnel on both machines:
systemctl enable --now wg-quick@wg0
ping -c 3 10.9.0.1 # from the node
4. Check the packet size the tunnel really carries. Run from the VPS:
for s in 1252 1212 1172; do ping -M do -c 2 -W 1 -s $s 10.9.0.2 >/dev/null 2>&1 && echo "$((s+28)) ok" || echo "$((s+28)) FAIL"; done
1280 ok must appear. If it fails, lower MTU in both configs to the largest size that passes and restart the tunnel. Do not skip this step: when the packet size is too large, as it can be with WireGuard's default MTU of 1420, PoC and small requests still pass, but inference requests hang for about 60 seconds and fail.
5. Test the new address before you switch. The old address still works at this point. From any other machine:
head -c 6000 /dev/zero | tr '\0' 'a' > /tmp/big.txt
curl -s -m 20 -o /dev/null -w "small: %{http_code} in %{time_total}s\n" http://F_IP:8000/v1/versions
curl -s -m 20 -o /dev/null -w "large: %{http_code} in %{time_total}s\n" -X POST http://F_IP:8000/v1/chat/completions -H 'Content-Type: application/json' --data-binary @/tmp/big.txt
Both must answer within a few seconds. The large request returns an error status, which is fine. A timeout or 000 means the packet size is still wrong.
6. Switch the address as described in the rules above, using http://F_IP:8000 and tcp://F_IP:5000.
7. After one full PoC on the new address, close ports 8000 and 5000 on the node's old public address.
To roll back: send the transaction with the old address, restore config.env, recreate api and node, and run wg-quick down wg0.
Operating notes
- Outgoing connections from your node still use its own address, so keep the baseline firewall in place there.
- All incoming traffic passes through the VPS. Monitor it and keep a spare ready.
- The node's proxy sees real client addresses through the VPS, so its own per-client limits keep working.
- The connection limit on the VPS, 50 new connections per second per address, is a starting value. Raise it if several of your legitimate clients share one public address.
Option C: Cloudflare with a paid Spectrum subscription
Cloudflare's standard proxy (Free, Pro and Business plans) supports a fixed list of web ports, which does not include 8000, and does not carry P2P traffic on port 5000. Cloudflare Spectrum covers both: it forwards any TCP port to your node without reading the content.
- Plan. Custom TCP ports need an Enterprise plan with Spectrum as a paid add-on; see Spectrum protocols per plan. The price is by quote from Cloudflare sales. It is typically the most expensive of the three options.
- Setup. Create one Spectrum application for TCP 8000 and one for TCP 5000, both pointing at your node. Set
PUBLIC_URLandP2P_EXTERNAL_ADDRESSto the Spectrum hostname. Move the node to a new IP and allow ports 8000 and 5000 on it only from Cloudflare's IP ranges. - Limits. Spectrum covers incoming traffic only: your node's outgoing connections still show its real IP to other nodes. The node's proxy sees Cloudflare addresses rather than client addresses, so its per-client rate limits apply to Cloudflare addresses, not to individual clients.
Check that it works
- The chain shows your new address:
curl -s http://<node>:8000/chain-api/productscience/inference/inference/participant/<your address>. The epoch participant list follows at the next epoch. - Small and large requests to the new address answer within a few seconds (step 5 of Option B).
- The Gonka proxy logs show many different client IPs, not one.
- The chain node is not catching up, and your ML nodes still reach port 9100.
- One full PoC passes with normal weight.
- Devshard requests routed to you finish. A request that hangs for about 60 seconds and then drops points to packet size.
During an attack
- Write down the start and end time in UTC, the target address and the port.
- If the flood comes from a few addresses, drop them before connection tracking:
iptables -t raw -I PREROUTING -s <source address or subnet> -j DROP. Ask your provider to block the same sources upstream. - Open a ticket with your provider: ask them to filter the attack and to confirm the time window and ports.
- Report the attack to the support agent run by Millcreek R&D, one of the teams contributing to Gonka: @TechSupportEngineerOps in Telegram. Send the start and end time, the port, your node address, the source addresses, and whether it overlapped with PoC. The agent collects reports from hosts and can share what other hosts are seeing and general recommendations.