Amazon EC2 finally support static IP addresses
April 2nd, 2008
To enable the static IP addresses function , you need to download the latest Amazon EC2 Command-Line Tools, the download link of it is http://developer.amazonwebservices.com/connect/entry.jspa?externalID=351&categoryID=88
after download, I recommend to unzip it to a folder call ec2 under your home path
1 2 3 |
mkdir ~/ec2 cd ~/ec2 unzip ec2-api-tools.zip |
you can now see a folder call ec2-api-tools-1.3-19403 under the ec2 folder.
now it is time to update the .profile , so that EC2 tool can find the library that it use.
you have to download the private and public cert from amazon
1 2 3 4 5 |
nano ~/.profile export PATH=~/ec2/ec2-api-tools-1.3-19403/bin:$PATH export EC2_HOME=~/ec2/ec2-api-tools-1.3-19403 export EC2_CERT=~/.ec2/cert-xxxxxxxxx.pem export EC2_PRIVATE_KEY=~/.ec2/pk-yyyyyy.pem |
then you can start a new console so that the profile update will be effective.
you can now allocate a new IP address for your account.
1 2 |
Chris:~ chrischan$ ec2-allocate-address ADDRESS 75.101.139.212 |
This new IP 75.101.140.212 is not bundle to any AMI instance yet.
You have to manually assign this IP address to a instance
First, you need to know the instance that you have already started. you can use the following command
1 2 3 4 5 |
Chris:~ chrischan$ ec2-describe-instances RESERVATION r-3c1bea55 073126868754 default INSTANCE i-7124dd30 ami-5035d079 ec2-67-202-34-115.compute-1.amazonaws.com domU-12-31-38-00-6D-98.compute-1.internal running 0m1.small 2008-03-05T15:51:36+0000 us-east-1a |
you can see that the instance id is i-7124dd30, we can then assign the IP to that instance
1 2 |
Chris:~ chrischan$ ec2-associate-address 75.101.140.212 -i i-7124dd30 ADDRESS 75.101.140.212 i-7124dd30 |
If you want to check the address allocation status, you can use the follow command
1 2 |
Chris:~ chrischan$ ec2-describe-addresses ADDRESS 75.101.140.212 i-7124dd30 |
for any time if you want to free the IP , you can use
ec2-release-address IP-address |
If you want to assign the existing IP address to a new instance , you can use ec2-associate-address, but this time , you assign the new instance IP, and the existing IP address bundling will remove, so the single IP address will always only bundle to one instance.
Also, a instance can only have one IP address assocate to it , so when you assign a new IP address to a instance, all the existing IP bundling will be removed. And all the IP address in this status will start to charge you account. So whenever any IP allocate has finished , please make to use ec2-describe-addresses to check the IP address bundling status.

Sorry, comments are closed for this article.