
Understanding AWS VPC Traffic Mirroring
How VPC Traffic Mirroring copies and filters packets for network analysis on AWS.
Cloud Engineer | AWS | Generative AI & Agentic AI
Introduction
As part of my AWS Networking and Security learning journey, I recently completed the AWS SimuLearn lab: Traffic Mirroring .
In my previous lab, I explored VPC Flow Logs and Amazon CloudWatch to monitor network traffic.
This time, I learned how to go beyond flow-level monitoring and observe network traffic at the packet level using Amazon VPC Traffic Mirroring.
1. What Is Traffic Mirroring?
Traffic Mirroring is an Amazon VPC feature that copies network packets from a network interface (ENI) and sends them to a separate destination for monitoring and analysis.
The lab consisted of two EC2 instances:
- Source Server: Generates network traffic.
- Target Server: Receives mirrored packets for analysis.
The architecture can be simplified as follows:
Source EC2 ──────────> Internet | | Mirrored traffic vTarget EC2(Packet Analysis)One important realization was that the original traffic does not need to pass through the Target EC2.
The target receives a copy of the selected packets while the original traffic continues along its normal network path.
This is known as out-of-band monitoring.
2. Understanding the Core Components
Initially, I was confused about why Traffic Mirroring required several separate resources.
After completing the configuration, I understood their individual responsibilities.
Component | Responsibility |
|---|---|
Mirror Source | Identifies the ENI to monitor |
Mirror Target | Defines where copied packets are sent |
Mirror Filter | Determines which packets are copied |
Mirror Session | Connects the source, target, and filter |
In the lab, I created a mirror target named
MyTarget , a filter named EgressTraffic , and a session named EgressOnly .Creating a target or filter alone does not start traffic mirroring. The session establishes the relationship between these components.
This separation allows monitoring configurations to be reused and managed independently.
3. Understanding Traffic Mirror Filters
The initial outbound filter used the following configuration:
Configuration | Value |
|---|---|
Rule number | 100 |
Direction | Outbound |
Action | Accept |
Protocol | ICMP |
Source CIDR | 10.0.0.0/24 |
Destination CIDR | 0.0.0.0/0 |
This rule selects outbound ICMP traffic from the monitored ENI with a source address within
10.0.0.0/24 , regardless of its IPv4 destination.An important distinction is the meaning of Accept and Reject.
Unlike Security Groups or Network Firewall rules, Traffic Mirror Filter rules do not determine whether the original packet is allowed to reach its destination.
Instead:
- Accept: Copy the matching packet.
- Reject: Do not copy the matching packet.
The original traffic is still governed by the existing networking and security configuration.
4. Why Does Mirrored ICMP Traffic Use UDP Port 4789?
This was one of the most interesting concepts I encountered during the lab.
The source generates ICMP traffic using ping, but the target captures mirrored traffic using UDP port 4789.
Why are the protocols different?
AWS encapsulates mirrored packets using VXLAN before delivering them to the target.
Mirrored Packet+------------------------+| Outer IP Header || UDP Header (4789) || VXLAN Header (VNI 100) |+------------------------+| Original Packet Copy || IP Header || ICMP Header || Payload |+------------------------+The original ICMP packet is carried inside the VXLAN encapsulation.
The lab also introduced the VXLAN Network Identifier (VNI), which was configured with the value
100 .I learned to think of VXLAN as a transport envelope and VNI as a label inside that envelope.
The target can use packet analysis tools such as
tcpdump to inspect the received packets.For example, assuming the network interface is named
ens5 :sudo tcpdump -nni ens5 -vvv udp dst port 4789The lab also introduced VXLAN decapsulation using a Linux virtual network interface and hexadecimal payload inspection.
Although I still need to explore these packet analysis techniques further, I now understand how AWS delivers mirrored packets to a monitoring appliance.
5. Testing and Restricting Mirrored Traffic
The Practice section used two public IP addresses to generate ICMP traffic:
ping 1.1.1.1 -c 2ping 8.8.8.8 -c 2With the initial filter, outbound ICMP packets to both destinations matched the mirroring rules.
The DIY challenge required me to modify the destination CIDR:
Before: 0.0.0.0/0After: 1.1.1.1/32The expected behavior after this change was:
Traffic | Original Traffic | Mirrored |
|---|---|---|
Ping to 1.1.1.1 | Unaffected | Yes |
Ping to 8.8.8.8 | Unaffected | No |
HTTPS traffic | Unaffected | No |
I completed the assignment with the updated filter configuration.
This reinforced an important concept: selective mirroring allows us to collect only the traffic relevant to our monitoring objectives without changing the original packet forwarding behavior.
6. Traffic Mirroring vs. Other AWS Networking Services
After completing several AWS networking labs, I found it helpful to compare these services.
Service | Primary Responsibility |
|---|---|
AWS Network Firewall | Inspects and controls network traffic |
Route 53 DNS Firewall | Filters DNS queries |
VPC Flow Logs | Records network flow metadata |
CloudWatch Metrics | Monitors numerical measurements |
VPC Traffic Mirroring | Copies packets for detailed analysis |
VPC Flow Logs can tell me which IP addresses communicated, how many bytes were recorded, and whether traffic was accepted or rejected.
Traffic Mirroring can provide additional packet-level visibility, including headers and payloads, subject to packet truncation and encryption.
However, mirroring encrypted HTTPS traffic does not automatically decrypt its contents.
In production, I would also consider restricting access to mirrored traffic, selecting only necessary packets, and ensuring that the monitoring target is appropriately secured.
Final Thoughts
Before this lab, I mainly associated network monitoring with logs and metrics.
Now, I understand that AWS also provides packet-level visibility through Traffic Mirroring.
My biggest takeaway is that collecting network traffic and analyzing network traffic are two separate responsibilities.
AWS Traffic Mirroring delivers the packet copies, while monitoring tools running on the target perform the analysis.
I hope this article helps other AWS learners understand the relationship between Mirror Sources, Targets, Filters, Sessions, and VXLAN without getting overwhelmed by the underlying packet analysis commands.
Enjoyed reading this content? Let the author know!
Your likes, comments, shares, and saves help creators reach more builders.
Loading recommendations
Loading article