Skip to content

Instantly share code, notes, and snippets.

@siepkes
Created August 24, 2018 09:33
Show Gist options
  • Save siepkes/b4111f2ca4f9f08bab884c5dbe55a823 to your computer and use it in GitHub Desktop.
Save siepkes/b4111f2ca4f9f08bab884c5dbe55a823 to your computer and use it in GitHub Desktop.
[Unit]
Description=Configure resolvers
Requires=network-online.target
After=network-online.target
[Service]
Type=oneshot
User=root
Group=root
ExecStart=/usr/local/libexec/configure_resolvers
[Install]
WantedBy=multi-user.target
#!/usr/bin/env bash
# Adds 127.0.0.1 as the first name server to use. This is where Consul's DNS server runs in the VM.
# Obtains the rest of the DNS servers from Triton.
# Fetch all resolvers from Triton.
while : ${i:=-1}; ((i++)); SERVER=$(mdata-get sdc:resolvers.${i}); [ ${SERVER} ]; do
RESOLVERS=(${RESOLVERS[@]} ${SERVER})
done
DNS_DOMAIN=$(mdata-get sdc:dns_domain)
# Configure new resolvers in '/etc/resolve.conf'.
(
/bin/sed '/nameserver/d' /etc/resolv.conf 2>/dev/null
echo "nameserver 127.0.0.1"
for HOST in ${RESOLVERS[@]}; do
echo "nameserver ${HOST}"
done
echo "search $DNS_DOMAIN"
) > /etc/resolv.conf.new
mv /etc/resolv.conf{.new,}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment