Packet Mirroring
This page is an overview of Packet Mirroring in the Virtual Private Cloud (VPC) network. If you want to analyze your workloads' network traffic at scale and monitor network traffic using third-party virtual appliances, use Network Security Integration Packet Mirroring. For more information, see Out-of-band integration overview.
Packet Mirroring clones the traffic of specified instances in your VPC network and forwards it for examination. Packet Mirroring captures all traffic and packet data, including payloads and headers. The capture can be configured for both egress and ingress traffic, only ingress traffic, or only egress traffic.
The mirroring happens on the virtual machine (VM) instances, not on the network. Consequently, Packet Mirroring consumes additional bandwidth on the VMs.
Packet Mirroring is useful when you need to monitor and analyze your security status. It exports all traffic, not only the traffic between sampling periods. For example, you can use security software that analyzes mirrored traffic to detect all threats or anomalies. Additionally, you can inspect the full traffic flow to detect application performance issues. For more information, see the example use cases.
How it works
Packet Mirroring copies traffic from mirrored sources and sends it to a collector destination. To configure Packet Mirroring, you create a packet mirroring policy that specifies the source and destination.
Mirrored sources are Compute Engine VM instances that you can select by specifying subnets, network tags, or instance names. If you specify a subnet, all existing and future instances in that subnet are mirrored. You can specify one or more source types—if an instance matches at least one of them, it's mirrored.
Packet Mirroring collects traffic from an instance's network interface in the network where the packet mirroring policy applies. In cases where an instance has multiple network interfaces, the other interfaces aren't mirrored unless another policy has been configured to do so.
A collector destination is an instance group that is behind an internal load balancer. Instances in the instance group are referred to as collector instances.
When you specify the collector destination, you enter the name of a forwarding rule that is associated with the internal passthrough Network Load Balancer. Google Cloud then forwards the mirrored traffic to the collector instances. An internal load balancer for Packet Mirroring is similar to other internal load balancers except that the forwarding rule must be configured for Packet Mirroring. Any non-mirrored traffic that is sent to the load balancer is dropped.
Filtering
By default, Packet Mirroring collects all IPv4 traffic of mirrored instances. Instead of collecting all IPv4 traffic, you can use filters to expand the traffic that's collected to include all or some IPv6 traffic. You can also use filters to narrow the traffic that's mirrored, which can help you limit the bandwidth that's used by mirrored instances.
You can configure filters to collect traffic based on protocol, CIDR ranges (IPv4, IPv6, or both), direction of traffic (ingress-only, egress-only, or both), or a combination.
Policy order
Multiple packet mirroring policies can apply to an instance. The priority of a
packet mirroring policy is always 1000 and cannot be
changed. Identical policies are not supported. Google Cloud can send
traffic to any of the load balancers that have been configured with identical
packet mirroring policies. To predictably and consistently send mirrored traffic
to a single load balancer, create policies that have filters with
non-overlapping address ranges. If ranges overlap, set unique filter protocols.
Depending on each policy's filter, Google Cloud chooses a policy for each
flow. If you have distinct policies, Google Cloud uses the
corresponding policy that matches the mirrored traffic. For example, you might
have one policy that has the filter 198.51.100.3/24:TCP and another policy
that has the filter 2001:db8::/64:TCP:UDP. Because the policies are distinct,
there's no ambiguity about which policy Google Cloud uses.
However, if you have overlapping policies, Google Cloud evaluates
their filters to choose which policy to use. For example, you might have two
policies, one that has a filter for 10.0.0.0/24:TCP and another for
10.0.0.0/16:TCP. These policies overlap because their CIDR ranges overlap.
When choosing a policy, Google Cloud prioritizes policies by comparing their filter's CIDR range size.
Google Cloud chooses a policy based on a filter:
If policies have different but overlapping CIDR ranges and the same exact protocols, Google Cloud chooses the policy that uses the most specific CIDR range. Suppose the destination for a TCP packet leaving a mirrored instance is
10.240.1.4, and there are two policies with the following filters:10.240.1.0/24:ALLand10.240.0.0/16:TCP. Because the most specific match for10.240.1.4is10.240.1.0/24:ALL, Google Cloud uses the policy that has the filter10.240.1.0/24:ALL.If policies specify the same exact CIDR range with overlapping protocols, Google Cloud chooses a policy with the most specific protocol. For example, the following filters have the same range but overlapping protocols:
10.240.1.0/24:TCPand10.240.1.0/24:ALL. For matching TCP traffic, Google Cloud uses the10.240.1.0/24:TCPpolicy. The10.240.1.0/24:ALLpolicy applies to matching traffic for all other protocols.If policies have the same exact CIDR range but distinct protocols, these policies don't overlap. Google Cloud uses the policy that corresponds to the mirrored traffic's protocol. For example, you might have a policy for
2001:db8::/64:TCPand another for2001:db8::/64:UDP. Depending on the mirrored traffic's protocol, Google Cloud uses either the TCP or UDP policy.If overlapping policies have the same exact filter, they are identical. In this case, Google Cloud might choose the same policy or a different policy each time that matching traffic is re-evaluated against these policies. We recommend that you avoid creating identical packet mirroring policies.
VPC Flow Logs
VPC Flow Logs doesn't log mirrored packets. If a collector instance is on a subnet that has VPC Flow Logs enabled, traffic that is sent directly to the collector instance is logged, including traffic from mirrored instances. That is, if the original destination IPv4 or IPv6 address matches the IPv4 or IPv6 address of the collector instance, the flow is logged.
For more information about VPC Flow Logs, see Using VPC Flow Logs.
Key properties
The following list describes constraints or behaviors with Packet Mirroring that are important to understand before you use it:
Each packet mirroring policy defines mirrored sources and a collector destination. You must adhere to the following rules:
- All mirrored sources must be in the same project, VPC network, and Google Cloud region.
- A collector destination must be in the same region as the mirrored sources. A collector destination can be located in either the same VPC network as the mirrored sources or a VPC network connected to the mirrored sources' network using VPC Network Peering.
- Each mirroring policy can only reference a single collector destination. However, a single collector destination can be referenced by multiple mirroring policies.
All layer 4 protocols are supported by Packet Mirroring.
You cannot mirror and collect traffic on the same network interface of a VM instance because doing this would cause a mirroring loop.