Created
June 27, 2017 18:27
-
-
Save sjmcgrath/1f078656e168d8339ef3de8132096bc8 to your computer and use it in GitHub Desktop.
Using EC2 metadata determine resolver IP as VPC base + 2.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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