Skip to content

Instantly share code, notes, and snippets.

@dialt0ne
Created December 17, 2015 22:44
Show Gist options
  • Star 14 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dialt0ne/53676f891d6f632c078f to your computer and use it in GitHub Desktop.
Save dialt0ne/53676f891d6f632c078f to your computer and use it in GitHub Desktop.
Get AmazonProvidedDNS IP address from the EC2 meta-data
MAC_ADDR=`curl -s http://169.254.169.254/latest/meta-data/mac`
CIDR_FULL=`curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/${MAC_ADDR}/vpc-ipv4-cidr-block`
CIDR_BASE=`echo ${CIDR_FULL} | cut -d/ -f1 | cut -d\. -f1-3`
LAST_OCTET=`echo ${CIDR_FULL} | cut -d/ -f1 | cut -d\. -f4`
DNS_OCTET=`expr ${LAST_OCTET} + 2`
DNS_IP="${CIDR_BASE}.${DNS_OCTET}"
echo $DNS_IP
@smougenot
Copy link

dns server generic ip is 169.254.169.253 (a.k.a no need to compute the ip with range +2)

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