Skip to content

Instantly share code, notes, and snippets.

@emrahgunduz
Created December 22, 2016 16:54
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 emrahgunduz/a2bb1d03ed73d37aac9c0f13144f9f03 to your computer and use it in GitHub Desktop.
Save emrahgunduz/a2bb1d03ed73d37aac9c0f13144f9f03 to your computer and use it in GitHub Desktop.
Add multiple public ips to ec2 instance route
#!/bin/bash
#add routes for secondary IP addresses
MAC_ADDR=$(ifconfig eth0 | sed -n 's/.*ether \([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/20
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment