AWS Solutions Architect Associate Certification

Services Networking

Elastic IP Demo

In this guide, we demonstrate how to use Elastic IPs with an AWS EC2 instance. Before you begin, ensure that you have the following pre-configured in your AWS environment:

  • A Virtual Private Cloud (VPC)
  • A public subnet (configured with an attached gateway)
  • A server deployed to the public subnet named "my server" that initially receives a dynamic public IP address

Initial Setup

Make sure that your server, "my server", is running on a public subnet with an automatically assigned IP address before proceeding. This demo assumes that the initial public IP is 52.90.159.117.

Demonstrating Dynamic IP Behavior

Before configuring an Elastic IP, it's important to understand how dynamic public IP addresses behave. Follow these steps:

  1. Navigate to the EC2 dashboard.
  2. Stop the instance and wait until it shows a "stopped" state (this may take a few minutes).
  3. Notice that the public IP address is no longer displayed.
  4. Start the instance again.
  5. Observe that the new public IP address is different and may begin with a "3" rather than a "5".

The image shows an AWS EC2 management console with a list of instances, where one instance named "myserver" is running. Details about the instance, such as its ID, state, type, and IP addresses, are displayed.

This behavior indicates that the public IP is dynamic. Every time the instance is restarted, it receives a new public IP, which can disrupt access if the IP is hardcoded in client configurations.

Introducing Elastic IPs

AWS offers Elastic IPs as a solution to the issue of changing public IPs. An Elastic IP is a static public IP address that remains associated with your account regardless of the instance's state. Whether the server is stopped or restarted, the Elastic IP remains constant, ensuring uninterrupted access.

Allocating an Elastic IP

To reserve an Elastic IP, complete the following steps:

  1. Navigate to the EC2 dashboard.
  2. Click on "Elastic IPs."
  3. Select "Allocate Elastic IP address."
    AWS will automatically choose an IP address from the Amazon pool of IPv4 addresses and assign it to your account.

The image shows an AWS console page for allocating an Elastic IP address, with options for selecting a network border group and public IPv4 address pool. There are also sections for global static IP addresses and optional tags.

After the allocation, assume the assigned Elastic IP is 35.173.92.86. This static IP is now reserved exclusively for your account.

Associating the Elastic IP with an Instance

Once you have allocated an Elastic IP, associate it with your instance by following these steps:

  1. In the EC2 dashboard, select the Elastic IP and click on “Actions.”
  2. Choose "Associate Elastic IP address."
  3. Specify the instance (or network interface) that the IP should be associated with.
    If the instance has multiple private IP addresses, select the appropriate one (in this demo, there is only one).

The image shows an AWS console interface for associating an Elastic IP address with an instance. It includes options to choose the instance and private IP address, with a button to associate the IP.

On successful association, the instance now displays the Elastic IP (35.173.92.86) as its public IP address.

The image shows an AWS EC2 Management Console with a list of instances, highlighting one named "myserver" that is currently running. It provides details such as the instance ID, public IPv4 address, and instance type.

Verifying Connectivity

To test that your Elastic IP is functioning correctly, run a ping test from your terminal:

C:\Users\sanje\Documents\scratch\aws-demo>clear
'clear' is not recognized as an internal or external command,
operable program or batch file.

C:\Users\sanje\Documents\scratch\aws-demo>ping 35.173.92.86

Pinging 35.173.92.86 with 32 bytes of data:
Reply from 35.173.92.86: bytes=32 time=22ms TTL=112
Reply from 35.173.92.86: bytes=32 time=21ms TTL=112
Reply from 35.173.92.86: bytes=32 time=15ms TTL=112
Reply from 35.173.92.86: bytes=32 time=19ms TTL=112

Ping statistics for 35.173.92.86:
    Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
    Minimum = 15ms, Maximum = 22ms, Average = 19ms

The successful ping confirms that the Elastic IP (35.173.92.86) is correctly routing traffic to your instance.

Ensuring Elastic IP Persistence

To confirm that the Elastic IP remains persistent across instance reboots:

  1. Stop the instance via the EC2 dashboard.
  2. Restart the instance.
  3. Verify that the public IP continues to be 35.173.92.86.

This persistence guarantees uninterrupted connectivity even when the instance is restarted.

Releasing an Elastic IP

If you no longer need the reserved Elastic IP and wish to avoid unnecessary charges, follow these steps to release it:

  1. In the EC2 dashboard, select your Elastic IP.
  2. Under "Actions," choose "Release Elastic IP."
    If you receive a prompt indicating that the IP cannot be released due to an active association, first disassociate the IP.
  3. After disassociating, release the Elastic IP address.
    The IP is now removed from your account and will no longer incur charges.

Release Caution

Before releasing your Elastic IP, ensure that no critical services rely on this IP address. Releasing an Elastic IP might lead to service interruptions.

Summary Table

Below is a quick reference table summarizing the key steps for working with Elastic IPs:

StepActionExpected Outcome
Dynamic IP DemonstrationStop and restart the instancePublic IP changes from 52.90.159.117 to a new value
Allocating an Elastic IPAllocate a new Elastic IP in EC2 dashboardA static IP (e.g., 35.173.92.86) is assigned to your account
Associating the Elastic IPAssociate the Elastic IP with your instanceThe instance now consistently uses the Elastic IP
Verifying ConnectivityPing the Elastic IPSuccessful replies confirm connectivity
Ensuring Elastic IP PersistenceReboot the instanceElastic IP remains unchanged
Releasing the Elastic IPDisassociate and release the Elastic IPElastic IP is removed from your account

By following these steps, you ensure your server uses a fixed public IP address, mitigating potential disruptions from dynamic IP changes.

For more detailed information about AWS EC2 and Elastic IPs, explore the AWS Documentation and AWS Elastic IP FAQs.

This concludes our demonstration on using Elastic IPs with AWS EC2 instances.

Watch Video

Watch video content

Previous
Elastic IP