How to get the VPC CIDR range from within an AWS Instance

amazon ec2amazon-vpcamazon-web-services

I'm trying to programatically set the routes that a vpn should push to clients, one of the main ones being the VPC network. Is there a way to get the VPC CIDR block from within my vpn instance?

Best Answer

You can get the VPC CIDR block by doing e.g.

$ metadata="http://169.254.169.254/latest/meta-data"
$ mac=$(curl -s $metadata/network/interfaces/macs/ | head -n1 | tr -d '/')
$ cidr=$(curl -s $metadata/network/interfaces/macs/$mac/vpc-ipv4-cidr-block/)
Related Topic