Skip to content

Instantly share code, notes, and snippets.

@arirubinstein
Last active December 27, 2015 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arirubinstein/7333161 to your computer and use it in GitHub Desktop.
Save arirubinstein/7333161 to your computer and use it in GitHub Desktop.
Amazon EC2 script to assign multiple public IPs automatically to box in VPC
#!/bin/bash
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root" 1>&2
exit 1
fi
MAC_ADDR=$(ifconfig eth0 | sed -n 's/.*HWaddr \([a-f0-9:]*\).*/\1/p')
IP=($(curl http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MAC_ADDR/local-ipv4s))
for ip in ${IP[@]:1}; do
echo "Adding IP: $ip"
ip addr add dev eth0 $ip/24
done
echo "Public IPs are now:"
curl http://169.254.169.254/latest/meta-data/network/interfaces/macs/$MAC_ADDR/public-ipv4s | tee our_public_ips.txt
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment