Skip to content

Instantly share code, notes, and snippets.

@sjmcgrath
Created June 27, 2017 18:27
Show Gist options
  • Save sjmcgrath/1f078656e168d8339ef3de8132096bc8 to your computer and use it in GitHub Desktop.
Save sjmcgrath/1f078656e168d8339ef3de8132096bc8 to your computer and use it in GitHub Desktop.
Using EC2 metadata determine resolver IP as VPC base + 2.
#!/bin/bash
MAC=$( curl -fs http://169.254.169.254/2016-09-02/meta-data/network/interfaces/macs/ )
VPC_CIDR=$( curl -fs http://169.254.169.254/2016-09-02/meta-data/network/interfaces/macs/${MAC%/}/vpc-ipv4-cidr-block/ )
BASE_IP=${VPC_CIDR%/*}
ABC_IP=${BASE_IP%.*}
D_IP=${BASE_IP##*.}
D_IP=$(( D_IP + 2 ))
RESOLVER_IP=${ABC_IP}.${D_IP}
echo $RESOLVER_IP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment