Traffic Mirroring on Linux with Iptables TEE: High-Performance Monitoring Without the Lag

Networking tutorial - IT technology blog
Networking tutorial - IT technology blog

Visibility Without the Performance Tax

Running a high-traffic production server often feels like flying blind. You need to inspect packets to catch threats or troubleshoot latency, but adding an inline proxy can slow down your application. In a physical data center, you’d just use a SPAN port on a Cisco or Juniper switch. But if you’re running on AWS, DigitalOcean, or a private Proxmox cluster, you probably don’t have access to the hardware switch.

Host-based traffic mirroring solves this problem. By using the Linux kernel to clone packets, you can send a copy of your traffic to a separate security node—like a Suricata IDS or a Zeek sensor—without getting in the way of the original data. It’s the closest thing to a physical tap in a virtualized world.

Why Iptables TEE is the Right Tool

Linux provides several ways to move packets, but the TEE target in iptables is uniquely efficient. Unlike a bridge, which sits in the middle of the path, TEE creates a “clone and forget” copy. It hands the original packet back to the networking stack almost instantly. In my testing on a standard 1Gbps link, the latency added to the original packet is usually under 5 microseconds—well below what most applications can even measure.

This approach keeps your production server lean. Since the heavy lifting of packet analysis happens on a different machine, your web server or database doesn’t lose CPU cycles to complex pattern matching or deep packet inspection.

How Packet Cloning Works Under the Hood

The TEE target lives inside the mangle table. This table is specifically designed for specialized packet alterations. When a packet hits a TEE rule, the kernel performs a quick four-step process:

  • It creates a bit-for-bit copy of the packet.
  • It adjusts the destination MAC or IP to point toward your monitoring gateway.
  • It pushes the copy out of the network interface.
  • It immediately releases the original packet to continue its journey.

Preparing Your Environment

Most modern distributions like Ubuntu 22.04, Debian 12, or Rocky Linux come with the TEE module pre-compiled. You just need to make sure it’s active.

# Check for the module
lsmod | grep xt_TEE
# Load it if it's missing
sudo modprobe xt_TEE

Our Lab Scenario

  • Production Server: 192.168.1.10 (eth0) – This is the source.
  • Monitoring Node: 192.168.1.50 – This is where we send the clones.

Implementation Steps

1. Cloning Inbound Traffic

To see requests coming from the outside world, we use the PREROUTING chain. This catches packets the moment they arrive at the network card.

sudo iptables -t mangle -A PREROUTING -i eth0 -j TEE --gateway 192.168.1.50

2. Cloning Outbound Traffic

Monitoring what your server sends back is just as important. It helps you spot data exfiltration or suspicious “phone home” behavior from compromised software. Use the POSTROUTING chain for this.

sudo iptables -t mangle -A POSTROUTING -o eth0 -j TEE --gateway 192.168.1.50

3. Precision Mirroring

Mirroring a full 10Gbps pipe will likely saturate your monitoring link and crush your disk I/O. Instead, focus on the high-risk ports. I usually mirror only web traffic (80, 443) and DNS (53) to keep the data manageable.

# Only mirror web traffic
sudo iptables -t mangle -A PREROUTING -i eth0 -p tcp -m multiport --dports 80,443 -j TEE --gateway 192.168.1.50

Configuring the Receiver

The monitoring server at 192.168.1.50 is about to receive thousands of packets that aren’t actually addressed to it. Normally, the Linux kernel would see the mismatched destination and drop them immediately. You must tell the interface to listen to everything.

Set the interface to promiscuous mode so the IDS can “see” the mirrored traffic:

sudo ip link set eth0 promisc on

Verify the stream is working by running tcpdump. You should see traffic with source and destination IPs that don’t belong to the monitoring box:

sudo tcpdump -i eth0 -n "not host 192.168.1.50"

Lessons from the Field

The MTU Trap

Cloud environments like OpenStack or AWS VPC often use a tight MTU of 1450 or 1400 bytes to account for VXLAN overhead. When TEE clones a packet, the resulting frame might exceed these limits if your routing adds extra headers. If you see your mirror working for small pings but failing for large file downloads, check your MTU settings.

CPU Overhead

While TEE is fast, it isn’t free. Cloning doubles the work for your network driver. Keep an eye on the ksoftirqd process using top. If you see a single CPU core hitting 80% or 90% usage, your rules are likely too broad. Use Iptables filters to narrow down the traffic to only what is strictly necessary for your security audit.

Persistence

Standard Iptables rules vanish after a reboot. Don’t forget to save your configuration. On Ubuntu, the iptables-persistent package is the standard way to handle this.

sudo apt-get install iptables-persistent
sudo netfilter-persistent save

Final Thoughts

Iptables TEE is a robust, kernel-level solution for anyone needing deep network visibility without the high cost of hardware taps. It works perfectly in virtualized environments where traditional SPAN ports aren’t an option. By selectively cloning your most critical traffic, you can feed your security stack the data it needs while keeping your production services fast and responsive.

Share: