Paul-Christian Volkmer 18bda9f1c6 Use dnsmasq and configure dns server config for clients
This will add a DNS config to the client configurations pointing to the
wireguard server. With this configuration, all DNS requests are sent
through the VPN and are no longer answered by the local DNS server.

Each client now has a hostname like <device>-client<id>.
2023-01-21 01:41:41 +01:00

24 lines
774 B
Bash
Executable File

#!/bin/bash
# Prepare and cleanup hosts file
mkdir hosts.d 2>/dev/null
echo -n "" > hosts.d/wg
NETWORK=$(cat $DEVICE.conf | grep Address | sed 's/Address = //g; s/\.[0-9\/]*,.*$//g')
NETWORK6=$(cat $DEVICE.conf | grep Address | sed 's/Address = //g; s/^.*, //g; s/\:[0-9a-f\/]*$//g')
# Print hosts file
echo "# IPv4 clients" >> hosts.d/wg
echo "$NETWORK.1 $DEVICE-server" >> hosts.d/wg
for i in {1..240}; do
if [ -f "$DEVICE-client_$i.conf" ]; then
echo "$NETWORK.$(($i+10)) $DEVICE-client$i" >> hosts.d/wg
fi
done
echo "# IPv6 clients" >> hosts.d/wg
echo "$NETWORK6:1 $DEVICE-server" >> hosts.d/wg
for i in {1..240}; do
if [ -f "$DEVICE-client_$i.conf" ]; then
echo "$NETWORK6:$(printf "%x" $(($i+10))) $DEVICE-client$i" >> hosts.d/wg
fi
done