github.com/Ilhicas/nomad@v1.0.4-0.20210304152020-e86851182bc3/e2e/terraform/packer/ubuntu-bionic-amd64/dnsconfig.sh (about) 1 #!/bin/bash 2 set -e 3 4 # These tasks can't be executed during AMI builds because they rely on 5 # instance-specific data. 6 7 mkdir -p /var/run/dnsmasq 8 mkdir -p /etc/dnsmasq.d 9 10 # Add hostname to /etc/hosts 11 echo "127.0.0.1 $(hostname)" | tee --append /etc/hosts 12 13 # this script should run after docker.service but we can't guarantee 14 # it's created docker0 yet, so wait to make sure 15 while ! (ip link | grep -q docker0) 16 do 17 sleep 1 18 done 19 20 # Use dnsmasq first and then docker bridge network for DNS resolution 21 DOCKER_BRIDGE_IP_ADDRESS=$(/usr/local/bin/sockaddr eval 'GetInterfaceIP "docker0"') 22 cat <<EOF > /tmp/resolv.conf 23 nameserver 127.0.0.1 24 nameserver $DOCKER_BRIDGE_IP_ADDRESS 25 EOF 26 cp /tmp/resolv.conf /etc/resolv.conf 27 28 # need to get the interface for dnsmasq config so that we can 29 # accomodate both "predictable" and old-style interface names 30 IFACE=$(/usr/local/bin/sockaddr eval 'GetDefaultInterfaces | attr "Name"') 31 32 cat <<EOF > /tmp/dnsmasq 33 port=53 34 resolv-file=/var/run/dnsmasq/resolv.conf 35 bind-interfaces 36 interface=docker0 37 interface=lo 38 interface=$IFACE 39 listen-address=127.0.0.1 40 server=/consul/127.0.0.1#8600 41 EOF 42 cp /tmp/dnsmasq /etc/dnsmasq.d/default 43 44 # need to get the AWS DNS address from the VPC... 45 # this is pretty hacky but will work for any typical case 46 MAC=$(curl -s --fail http://169.254.169.254/latest/meta-data/mac) 47 CIDR_BLOCK=$(curl -s --fail "http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MAC/vpc-ipv4-cidr-block") 48 VPC_DNS_ROOT=$(echo "$CIDR_BLOCK" | cut -d'.' -f1-3) 49 echo "nameserver ${VPC_DNS_ROOT}.2" > /tmp/dnsmasq-resolv.conf 50 cp /tmp/dnsmasq-resolv.conf /var/run/dnsmasq/resolv.conf 51 52 /usr/sbin/dnsmasq --test