Files
runtipi/apps/rego-tunnel/shared/start-dnsmasq.sh
alexz f1ba1f050d
Some checks failed
Test / test (push) Has been cancelled
new image structure for cisco-vpn and related scripts
2026-01-04 09:01:52 +00:00

39 lines
938 B
Bash

#!/bin/bash
set -euo pipefail
BRIDGE_NAME="${BRIDGE_NAME:-br-rego-vpn}"
BRIDGE_CIDR="${BRIDGE_CIDR:-100.100.0.1}"
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}"
if [[ "$BRIDGE_CIDR" != */* ]]; then
BRIDGE_CIDR="$BRIDGE_CIDR/24"
fi
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