Files
runtipi/apps/rego-tunnel/build/start-dnsmasq.sh
alexz 2d98ca843f
Some checks failed
Test / test (push) Has been cancelled
rego-tunnel: parameterize net + add DHCP static lease
2025-12-28 22:56:51 +00:00

35 lines
869 B
Bash

#!/bin/bash
set -euo pipefail
BRIDGE_NAME="${BRIDGE_NAME:-br-rego-vpn}"
BRIDGE_CIDR="${BRIDGE_CIDR:-100.100.0.1/24}"
VM_NET_IP="${VM_NET_IP:-100.100.0.2}"
VM_MAC="${VM_MAC:-52:54:00:12:34:56}"
LEASE_TIME="${LEASE_TIME:-12h}"
DNS_SERVERS="${DNS_SERVERS:-1.1.1.1,8.8.8.8}"
GATEWAY_IP="${BRIDGE_CIDR%%/*}"
mkdir -p /etc/dnsmasq.d
cat > /etc/dnsmasq.d/rego.conf <<EOF
interface=${BRIDGE_NAME}
bind-interfaces
except-interface=lo
dhcp-authoritative
log-dhcp
dhcp-range=${VM_NET_IP},${VM_NET_IP},${LEASE_TIME}
dhcp-option=option:router,${GATEWAY_IP}
dhcp-option=option:dns-server,${DNS_SERVERS}
# Static lease for the VM
# (VM must use DHCP for this to take effect)
dhcp-host=${VM_MAC},${VM_NET_IP}
EOF
echo "[rego-tunnel] dnsmasq on ${BRIDGE_NAME} gateway=${GATEWAY_IP} lease ${VM_MAC} -> ${VM_NET_IP}"
exec dnsmasq --no-daemon --conf-file=/etc/dnsmasq.d/rego.conf