Lesson 4 of 6 Amazon EC2

Understanding EC2 Network Interfaces, Addresses and Accelerated Networking

This lesson explains how instances connect to their VPC through network interfaces, and how interfaces, IP addresses and accelerated networking explain many failover and performance questions.

Learning outcomes

After completing this lesson, you will be able to:

  • Describe elastic network interfaces and IP address types.
  • Distinguish enhanced networking from Elastic Fabric Adapter.
  • Describe how instances are reached without exposure to the internet.

Interfaces and addresses

An instance connects to its VPC through one or more elastic network interfaces (ENIs), virtual network cards that carry private IP addresses, security groups and a MAC address. A secondary ENI can be detached and attached to another instance in the same Availability Zone, so its addresses move with it, which supports simple failover or software licensed to a MAC address.

Instances use several kinds of address. A private IPv4 address stays with the instance for its whole life, including stops and starts. A public IPv4 address is assigned at launch in a public subnet, but it is released when the instance stops, so it changes on the next start; every public IPv4 address is charged hourly. An Elastic IP address is a static public address that you keep until you release it and can move between instances, for clients that need a fixed address. IPv6 addresses are globally unique; an egress-only internet gateway lets them make outbound connections only. The following table summarises these components.

FeatureBehaviour
Elastic network interface (ENI)A virtual network card with private IPs, security groups and a MAC address; a secondary ENI can be moved to another instance in the same AZ for failover
Private IPv4 addressKept for the life of the instance, including stop and start
Public IPv4 addressAssigned at launch in a public subnet; released on stop; every public IPv4 address is charged hourly
Elastic IP addressA static public IPv4 address you own until released, movable between instances
IPv6Globally unique addresses; outbound-only access through an egress-only internet gateway

The following diagram shows a secondary ENI moving from a failed instance to a standby.

Failover by moving a secondary elastic network interface. The ENI carries its private IP address, security groups and MAC address. When the primary instance fails, the ENI is detached and attached to a standby instance in the same Availability Zone, so clients and MAC-licensed software see the same address.
The address is illustrative. An Elastic IP address associated with the ENI moves with it.
True or false

Addresses and interfaces

Exam skills 3.4.3 · 2.2.7

Check how EC2 addresses and network interfaces behave.

Log in to try this activity Interactive activities are free with an account.

Accelerated networking

Two features improve EC2 network performance beyond the standard. Enhanced networking, through the Elastic Network Adapter (ENA), gives higher bandwidth, more packets per second and lower latency by using hardware-assisted networking. It is enabled by default on current instance types and benefits every workload.

The Elastic Fabric Adapter (EFA) adds an operating-system bypass to ENA, letting applications that use the MPI or NCCL libraries communicate between instances without going through the kernel. This gives the very low, consistent latency that tightly coupled HPC simulations and distributed machine learning training need. The following table summarises the two features.

FeatureWhat it givesUse for
Enhanced networking (ENA)Higher bandwidth, more packets per second and lower latency; on by default on current instancesAll workloads
Elastic Fabric Adapter (EFA)ENA plus OS-bypass for MPI and NCCLTightly coupled HPC and distributed ML training

Network bandwidth grows with instance size, and instances in a cluster placement group get the highest node-to-node throughput.

Scenario questions

Accelerated networking

Exam skills 3.2.3

Choose the networking feature for each workload.

Log in to try this activity Interactive activities are free with an account.

Accessing instances

Instances can be administered without exposing them to the internet. AWS Systems Manager Session Manager gives shell access with no SSH keys, no inbound ports and no public IP addresses; access is controlled with IAM and sessions are logged. EC2 Instance Connect Endpoint allows SSH connections to instances in private subnets without a bastion host.

Code running on an instance learns about its environment from the instance metadata service, which provides the instance's addresses, its Availability Zone and the temporary credentials of its IAM role. Instances should require IMDSv2, which protects these credentials against server-side request forgery.

Worked example

Failing over a licensed application

A legacy application's licence is tied to a MAC address and a fixed IP. If its instance fails, a standby instance must take over within minutes.

OptionResult
Elastic IP moved to the standbyKeeps the public IP, but the MAC address changes
Secondary ENI moved to the standbyKeeps the private IP, MAC address and security groups

The licence is bound to a secondary ENI, and a script moves the interface to the standby instance in the same AZ on failure. For new applications, a load balancer and Auto Scaling avoid the need for fixed addresses altogether.

Check yourself

What does an Elastic Fabric Adapter add to enhanced networking?

Show answer

OS-bypass communication for tightly coupled HPC and machine learning applications, with lower and more consistent latency between instances.

Exam Tips

Remember for the exam

  • For a static public IPv4 address that survives stop and start, use an Elastic IP address.
  • To fail over quickly by moving an IP address and security groups, move a secondary ENI to a standby instance.
  • For tightly coupled HPC needing OS-bypass networking, use the Elastic Fabric Adapter.
  • To reach private instances without bastions or open ports, use Session Manager.
  • Public IPv4 addresses are released when an instance stops and are charged while assigned.