Skip to content

Instantly share code, notes, and snippets.

@rokiden
Last active December 20, 2022 20:01
Show Gist options
  • Save rokiden/4ff0afc8de93389258e9ce6e45d961b0 to your computer and use it in GitHub Desktop.
Save rokiden/4ff0afc8de93389258e9ce6e45d961b0 to your computer and use it in GitHub Desktop.
linuxserver/wireguard custom script configuring coredns with domain zone and peers
#!/usr/bin/with-contenv bash
CONFIG_DIR="/config"
if [ -z "$COREDNS_ZONE" ]; then
COREDNS_ZONE="wg.net"
fi
echo "**** CoreDNS hosts zone $COREDNS_ZONE ****"
echo "$COREDNS_ZONE {" > $CONFIG_DIR/coredns/hosts.conf
echo " hosts {" >> $CONFIG_DIR/coredns/hosts.conf
echo " " `grep Address $CONFIG_DIR/wg0.conf | awk '{print $NF}'` gate.$COREDNS_ZONE | tee -a $CONFIG_DIR/coredns/hosts.conf
for f in `ls $CONFIG_DIR/peer*/peer*.conf`; do
name=`basename $f .conf | sed 's/^peer_*//'`
echo " " `grep "Address" $f | awk '{print $NF}'` $name.$COREDNS_ZONE | tee -a $CONFIG_DIR/coredns/hosts.conf
done
echo " }" >> $CONFIG_DIR/coredns/hosts.conf
echo "}" >> $CONFIG_DIR/coredns/hosts.conf
if [[ -z `grep /config/coredns/hosts.conf $CONFIG_DIR/coredns/Corefile` ]]; then
echo "**** CoreDNS hosts patch Corefile ****"
echo 'import /config/coredns/hosts.conf' >> $CONFIG_DIR/coredns/Corefile
fi
@rokiden
Copy link
Author

rokiden commented Dec 20, 2022

wget https://gist.githubusercontent.com/rokiden/4ff0afc8de93389258e9ce6e45d961b0/raw/linuxserver-wireguard-coredns-hosts.sh
docker run --name=wg_test --restart unless-stopped -p 51820:51820/udp \
--cap-add=NET_ADMIN --cap-add=SYS_MODULE -v /lib/modules:/lib/modules \
-e PEERS=a,b -e COREDNS_ZONE=wg.net \
-v `pwd`/linuxserver-wireguard-coredns-hosts.sh:/custom-cont-init.d/hosts.sh \
lscr.io/linuxserver/wireguard

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment