Shows how we can map single EC2 instances to multiple Network Interfaces via Multiple Elastic IPs Show This is an introductory blog on how AWS ENI behaves with EC2 instances. If you are just started studying AWS, you may not use this feature straightaway but can be used in multiple technical use cases. It is always good to understand real concepts behind them. ENIs can be useful in following key reasons [1].
Elastic Network Interface (ENI)ENI is a logical networking component in a VPC that represents a Virtual Network Card. It can have the following attributes.
ENI — Key Features
The ScopeIn this blog, we are primarily focusing on how we can create multiple ENIs for a single EC2 instance and attach multiple Elastic IPs for each ENI private IP. Using this approach you can create multiple routes to the same instance application installations. We will discuss how we attach and detach ENIs to and from EC2 instances in a later blog. Task 1: Creating an EC2 instance and install Apache Create an EC2 instance (Amazon Linux, t2.micro) and install Apache on it. While creating the instance, create a Security Group (my-sg-1) and open port 80(HTTP) for future testing. When you create an EC2 instance it does attach a default network interface (primary ENI — eth0) to it (See Figure 3). Figure 3 — The EC2 instance created with the default ENITask 2: Allocate an Elastic IP Now lets allocate a new Elastic IP to the primary ENI. (If your subnet is public and it is configured to have auto generated public IP(s) then this is not needed. But here we are going to showcase, how Elastic IP(s) can be allocated to ENIs) Go to Elastic IP(s) → Click “Allocate Elastic IP Address” → Select Amazon Pool of IPv4 addresses →Click Allocate (See Figure 4) Figure 4 —Allocate a new Elastic IPTask 3: Associate the created Elastic IP to the primary/default ENI Go to Elastic IP Addresses → Click Actions button and select Associate Elastic IP → Select Resource Type as Network Interface → Select the Primary Network Interface that you have created from the select Network Interface search box → Click Associate. Figure 5 — Associate Elastic IP to the primary/ default ENITask 4: Lets run the EC2 instance Apache installation using the Elastic IP via the primary / default ENI Lets try to run the instance now with the assigned Elastic IP. You should see something similar to this. Here the index.html has a dummy text “Testing ENI” (See Figure 6). Figure 6 — Running an application via primary/ default ENINow, lets try to create another ENI and attach an Elastic IP with a new Security Group attached to it. This allows us to navigate the same instance via a different network address (new Elastic IP). Task 5: Create the additional ENI (second ENI) As a prerequisite, create another Security Group (my-sg-2) without allowing any ports to it. Now, create the additional ENI. Go to Network Interfaces → Click Create Network Interface → Select the same subnet that you created the EC2 instance → Select Auto Assign for the IPv4 Private IP → Select the Security Group (my-sg-2) → Create ENI (See Figure 7). Figure 7 — Creating an additionalENITask 6: Create another Elastic IP Figure 8 — Creating an Elastic IP for the additional ENITask 7: Associate the Elastic IP (created under step 6) to the additional ENI Figure 9 — Associate Elastic IP to the additional ENITask 8: Attach the additional ENI to the EC2 instance. However, in order to attach this additional ENI to the EC2 instance, you are required to do the following configuration. Go to EC2 instances → Select the EC2 instance → Select Actions → Select Networking → Select Attach Network Interface and select second ENI you have created (See Figure 10). Figure 10The ConclusionFinally, as a result of the above exercise, the EC2 instance is now attached with two ENIs.
Now you would see something similar to the following. Figure 10 — The EC2 instance with both eth0 and eth2References
What do network interfaces do?A network interface is the network-specific software that communicates with the network-specific device driver and the IP layer in order to provide the IP layer with a consistent interface to all network adapters that might be present.
How do I add a network interface to EC2?From the EC2 menu Network & Security > Network Interfaces.. you should already see one NIC for the LoadMaster which would be eth 0. select "Create network interface". Select "Actions" and attach the new interface to the LoadMaster.. Can EC2 have multiple network interfaces?A ec2 instance can have multiple network interfaces in multiple subnets but they must all be in the same VPC.
Why is Eni needed?Essentially, ENIs are virtual network cards you can attach to your EC2 instances. They are used to enable network connectivity for your instances, and having more than one of them connected to your instance allows it to communicate on two different subnets.
|