diff options
Diffstat (limited to 'relay')
| -rw-r--r-- | relay/install-bitflash-relay.sh | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/relay/install-bitflash-relay.sh b/relay/install-bitflash-relay.sh index 77a46b2..fd901ac 100644 --- a/relay/install-bitflash-relay.sh +++ b/relay/install-bitflash-relay.sh | |||
| @@ -295,6 +295,25 @@ echo ">> building bitflashd" | |||
| 295 | g++ -std=gnu++14 -O2 -pthread bitflashd.cpp btfrv.cpp -o bitflashd | 295 | g++ -std=gnu++14 -O2 -pthread bitflashd.cpp btfrv.cpp -o bitflashd |
| 296 | echo ">> build OK: $DIR/bitflashd" | 296 | echo ">> build OK: $DIR/bitflashd" |
| 297 | 297 | ||
| 298 | # Basic anti-flood firewall rules (idempotent). These soak up single-source | ||
| 299 | # connection floods; volumetric DDoS still needs provider-level protection. | ||
| 300 | # Limits are generous so many users behind one CGNAT public IP aren't blocked. | ||
| 301 | if command -v iptables >/dev/null 2>&1; then | ||
| 302 | echo ">> applying connection rate-limit on port $PORT" | ||
| 303 | # Cap concurrent connections per source IP (stops one IP hogging thousands) | ||
| 304 | iptables -C INPUT -p tcp --dport "$PORT" -m connlimit --connlimit-above 200 --connlimit-mask 32 -j REJECT --reject-with tcp-reset 2>/dev/null || \ | ||
| 305 | iptables -A INPUT -p tcp --dport "$PORT" -m connlimit --connlimit-above 200 --connlimit-mask 32 -j REJECT --reject-with tcp-reset | ||
| 306 | # Cap NEW-connection rate per source IP (stops connection floods) | ||
| 307 | iptables -C INPUT -p tcp --dport "$PORT" -m conntrack --ctstate NEW -m hashlimit \ | ||
| 308 | --hashlimit-name btfrelay --hashlimit-mode srcip --hashlimit-above 60/min --hashlimit-burst 100 -j DROP 2>/dev/null || \ | ||
| 309 | iptables -A INPUT -p tcp --dport "$PORT" -m conntrack --ctstate NEW -m hashlimit \ | ||
| 310 | --hashlimit-name btfrelay --hashlimit-mode srcip --hashlimit-above 60/min --hashlimit-burst 100 -j DROP | ||
| 311 | # Persist across reboots if the tooling is present | ||
| 312 | command -v netfilter-persistent >/dev/null 2>&1 && netfilter-persistent save >/dev/null 2>&1 || true | ||
| 313 | else | ||
| 314 | echo ">> iptables not found; skipping rate-limit (host on a provider with anti-DDoS)" | ||
| 315 | fi | ||
| 316 | |||
| 298 | # systemd service so it survives reboots (skipped if systemd is absent) | 317 | # systemd service so it survives reboots (skipped if systemd is absent) |
| 299 | if command -v systemctl >/dev/null 2>&1 && [ -d /etc/systemd/system ]; then | 318 | if command -v systemctl >/dev/null 2>&1 && [ -d /etc/systemd/system ]; then |
| 300 | cat > /etc/systemd/system/bitflashd.service <<EOF | 319 | cat > /etc/systemd/system/bitflashd.service <<EOF |