Wednesday, November 12, 2008

How to create an Elastic IP and associate that IP with an Instancenah

When you create an EC2 instance, it’s by default assigned two IP addresses to that instance. One is public IP address which one is mapped with the private IP address through Network Address Translator (Nat). you can surf an instance from another instance through private IP address and from the outer world you can access with the public IP address.

But Amazon provides another type of IP address which static IP and that one is designed for dynamic cloud computing. And this IP address will remain associated with your account until you release the IP.

The main thing I liked about the elastic IP address that it will provide zero downtime when you will want to switch one instance to another instance. You will don’t have to wait for DNS to resolve the IP address. Because at any moment you can change the instance that an elastic IP address has pointed.

Now let’s have a look how can you create an elastic IP address and point an instance by that IP address.

From the EC2 command line tools run the command

ec2-allocate-address

This command will return an IP address

Address xx.xx.xx.xx

Now you have to associate this address with an EC2 instance by using the following command

Suppose your instance is i-xxxxxxxxx

    ec2-associate-address –i i-xxxxxxxxx xx.xx.xx.xx

Now your elastic IP xx.xx.xx.xx is associated with the instance i-xxxxxxxxx

If you run the following command you will see that Address xx.xx.xx.xx is pointing the instance i-xxxxxxxxx

 
        ec2-describe-addresses xx.xx.xx.xx

From now on you will be able to access that instance by you elastic IP from the outer world

If you want to disassociate the elastic IP from the instance then run the following command

       ec2-disassociate-address xx.xx.xx.xx

Now you will get new public IP address for that instance. And your elastic IP has become free to point a new instance.

No comments: