#!/bin/sh set -e if [ -z "$NC_DOMAIN" ]; then echo "ERROR: NC_DOMAIN is not set" >&2 exit 1 fi LOCAL_IP="" # Determine the server's primary LAN IP - use the source address chosen by the kernel # for a route to a well-known public IP (1.1.1.1 is used purely to query the routing table; # no traffic is sent there). LOCAL_IP=$(ip route get 1.1.1.1 2>/dev/null | awk '{for(i=1;i<=NF;i++) if($i=="src") {print $(i+1); exit}}') if [ -z "$LOCAL_IP" ]; then LOCAL_IP=$(hostname -I 2>/dev/null | awk '{print $1}') fi if [ -z "$LOCAL_IP" ]; then echo "ERROR: Could not determine local IP address" >&2 exit 1 fi echo "Nextcloud AIO dnsmasq: resolving $NC_DOMAIN -> $LOCAL_IP" echo "Configure your router's DHCP to hand out $LOCAL_IP as the DNS server for LAN clients." mkdir -p /etc/dnsmasq.d cat > /etc/dnsmasq.d/nextcloud-aio.conf << EOF # Auto-generated by Nextcloud AIO dnsmasq container. # Resolves NC_DOMAIN (and all its subdomains) to this server's local IP. address=/$NC_DOMAIN/$LOCAL_IP # Bind only to the LAN interface to avoid conflicts with any system DNS resolver. bind-interfaces listen-address=$LOCAL_IP EOF exec dnsmasq --no-daemon --log-queries --conf-dir=/etc/dnsmasq.d