Created
July 3, 2013 16:51
-
-
Save kyle-johnson/5920407 to your computer and use it in GitHub Desktop.
Amazon EC2 VPC multiple IP setup under Ubuntu Linux (With multiple virtual interfaces on the same subnet) Put vpc.sh into your ip-up.d directory and then update your /etc/network/interfaces to have all virtual adapters. Then it's a matter of sudo /etc/init.d/networking restart
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
auto lo | |
iface lo inet loopback | |
auto eth0 | |
iface eth0 inet dhcp | |
auto eth1 | |
iface eth1 inet dhcp | |
# etc |
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 | |
# put this in /etc/network/if-up.d/100vpc and make it executable | |
TABLE=$((${IFACE:(-1)}+1)) | |
ip route add default via 10.0.0.1 dev $IFACE tab $TABLE | |
MAC_ADDR=$(ifconfig $IFACE | 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; do | |
echo "Adding IP: $ip" | |
ip addr add $ip/24 dev $IFACE | |
ip rule add from $ip/32 table $TABLE | |
done | |
ip route flush cache |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment