How can I associate two Elastic IP addresses to a single EC2 Ubuntu 22.04 instance?

0

We are migrating services from an Ubuntu 16.04 EC2 instance (Instance A) to an Ubuntu 22.04 instance (Instance B).

Both instances are in a VPC and both are in the same subnet.

Each instance currently has a single EIP associated with the instance and each instance has a single Elastic Network Interface attached.

Each instance hosts public-facing services at their respective EIP addresses.

Our objective is to host all public-facing services on Instance B and to support that we have duplicated those services on Instance B.

To complete the migration, we would like to take the EIP associated with Instance A (EIP A) and instead associate it with Instance B while maintaining the current EIP for Instance B (EIP B). Thus Instance B would be publicly accessible via either EIP A or EIP B.

Can this be done within a single EC2 Instance without a second Elastic Network Interface being attached?

If so, what are the steps?

If not, does it require a second Elastic Network Interface?

We did try creating a second Elastic Network Interface and attaching that to Instance B, then associated the Instance A EIP with it but it was unresponsive to server requests. Further reading indicated internal routing was required (https://repost.aws/knowledge-center/ec2-ubuntu-secondary-network-interface) and also suggested this could cause routing issues for outbound packets.

If the second network interface is required, what are the steps for an Ubuntu 22.04 EC2 instance?

Ultimately we will migrate all services to one IP address but for the transition period, we would like to maintain both.

4 Answers
4
  1. Create Additional Network Interfaces Go to the EC2 Dashboard:

Navigate to the "Network Interfaces" section. Click on "Create network interface". Assign a subnet. Choose or allocate an Elastic IP for each additional network interface. 2. Attach Network Interfaces to the EC2 Instance Select the EC2 instance to which you want to attach the additional network interfaces. Click "Actions" -> "Networking" -> "Manage network interfaces". Attach the additional network interfaces that you created. 3. Configure Networking on the EC2 Instance Once the network interfaces are attached, SSH into your EC2 instance and configure the networking.

Use the ifconfig or ip addr show command to list available network interfaces. Configure the interfaces with the appropriate IP addresses. You can edit the network configuration files in /etc/netplan/ for Ubuntu 22.04. Ensure proper routing configuration if necessary. 4. Update Security Groups and Firewall Rules Ensure that your security groups and firewall rules allow traffic from/to the additional Elastic IP addresses.

Go to the EC2 Dashboard. Navigate to the "Security Groups" section. Update the inbound and outbound rules of your security group to allow traffic from/to the additional IP addresses.

answered 11 days ago
0

Hello.

Setting up multiple Elastic IPs on your EC2 instance requires multiple ENIs.
In other words, you need to configure another ENI and configure EIP A for that ENI.
https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/MultipleIP.html

The settings themselves can be done using the method introduced in this blog.
https://dev.to/elngovind/adding-secondary-eni-private-ip-to-amazon-ec2-ubuntu-2204-for-ssh-5f2n

profile picture
EXPERT
answered 11 days ago
profile pictureAWS
EXPERT
reviewed 11 days ago
0

The number of IP addresses you can have on a single network interface is determined by the instance type https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-eni.html#AvailableIpPerENI

The sample aws ec2 describe-instance-types .... command is pretty useful, even the smallest instance type (t2.nano and t3.nano) can have two IPv4 addresses on an ENI.

profile picture
EXPERT
Steve_M
answered 11 days ago
0

Hi,

Associating multiple IP's on your EC2 instance requires Multiple ENI's Here i attached simple steps to setting up multiple IP's for a Ubuntu EC2 Servers through AWS Documentation https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/MultipleIP.html

This is the link for Adding a second private IP on EC2 Ubuntu 18.04 LTS instance https://easyscale.net/aws-ec2-ubuntu-18-04-secondary-ip-with-netplan/

answered 11 days ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions