Skip to content

IPVLAN for container networking: L2 vs L3 mode and when to pick it over MACVLAN

How IPVLAN shares the parent MAC while giving each child its own IP, the difference between L2 and L3 modes, and where IPVLAN beats MACVLAN in cloud and Wi-Fi environments.

IPVLAN solves the two problems that make MACVLAN awkward in real deployments: it uses only the parent NIC’s MAC address (so cloud VPCs and Wi-Fi accept the traffic) and the host can talk to its children without a shim. The cost is that IPVLAN children share a MAC, so any L2-aware policy on the upstream switch will treat them as one device — fine for L3 isolation, less so for traditional 802.1Q-keyed multi-tenancy. This article covers when IPVLAN beats MACVLAN, the L2 vs L3 mode tradeoff, and a working three-container setup.

How to verify

Inspect IPVLAN interfaces and modes:

ip -d link show
ip link show type ipvlan
ip neigh show
ip route show
tcpdump -ni eth0 host <child-ip>
ip -s link show ipvlan-app1

The ip -d link show output names the mode (ipvlan mode l2 or mode l3 or mode l3s); the choice of mode changes routing semantics for child traffic in important ways — verify before debugging connectivity.

What’s happening

IPVLAN, like MACVLAN, attaches virtual interfaces to a parent NIC. Unlike MACVLAN, every IPVLAN child uses the parent’s MAC. Frames leaving the box still carry that single source MAC; what disambiguates the children is their distinct IP addresses, demultiplexed at the IP layer.

There are three modes:

  • l2: children act like additional IPs on the same L2 broadcast domain as the parent. ARP requests from outside resolve to the parent MAC, and the kernel routes the reply to the right child. This is the most MACVLAN-like behaviour.
  • l3: children are isolated from each other at L2 entirely — no ARP, no broadcast. Routing happens via the host’s IP stack. Children must have routes to each other and to the gateway populated explicitly. This is the cloud-friendly mode because no L2 dependencies remain.
  • l3s (L3-symmetric): same as L3 but with full netfilter-aware forwarding, so iptables rules in FORWARD chain apply to inter-child traffic.

For Kubernetes nodes running on EC2 or Azure VMs, L3 mode is the canonical choice — it sidesteps every cloud-VPC anti-spoofing check and gives the host the equivalent of per-pod IPs without bridge overhead. The AWS VPC CNI uses an IPVLAN-like model under the hood for secondary IP attachments.

The procedure

  1. L3 mode setup for three container children. Parent eth0 is on 192.0.2.0/24; children get 10.99.0.10/32, 10.99.0.11/32, 10.99.0.12/32. We’ll route the /32 addresses to the kernel via host routes, with the upstream router pointed at eth0’s IP.

    ip link add ipvl-a link eth0 type ipvlan mode l3
    ip link add ipvl-b link eth0 type ipvlan mode l3
    ip link add ipvl-c link eth0 type ipvlan mode l3
    
    ip link set ipvl-a netns app-a
    ip link set ipvl-b netns app-b
    ip link set ipvl-c netns app-c
    
    ip -n app-a addr add 10.99.0.10/32 dev ipvl-a
    ip -n app-a link set ipvl-a up
    ip -n app-a route add default dev ipvl-a
    
    ip -n app-b addr add 10.99.0.11/32 dev ipvl-b
    ip -n app-b link set ipvl-b up
    ip -n app-b route add default dev ipvl-b
    
    ip -n app-c addr add 10.99.0.12/32 dev ipvl-c
    ip -n app-c link set ipvl-c up
    ip -n app-c route add default dev ipvl-c
  2. Enable IP forwarding on the host.

    sysctl -w net.ipv4.ip_forward=1
  3. Add the return path on the host. The host needs routes to each child so reply packets find them:

    ip route add 10.99.0.10/32 dev ipvl-a
    ip route add 10.99.0.11/32 dev ipvl-b
    ip route add 10.99.0.12/32 dev ipvl-c

    In L3 mode the child interface stays in the host namespace as a reference; the kernel demuxes by routed IP.

  4. Advertise the child prefix upstream. With L3 mode there is no ARP — the upstream router must have a route for 10.99.0.0/24 pointing at the host’s 192.0.2.x address, either via static route, BGP, or DHCP option-121 classless static routes.

  5. For Docker, the ipvlan driver supports both modes.

    docker network create -d ipvlan \
      --subnet=10.99.0.0/24 \
      -o parent=eth0 \
      -o ipvlan_mode=l3 \
      overlay_net
    docker run -d --network overlay_net --ip=10.99.0.10 nginx
  6. Persist with systemd-networkd. L3 mode is set in the .netdev:

    [NetDev]
    Name=ipvl-a
    Kind=ipvlan
    
    [IPVLAN]
    Mode=L3

Operational notes

  • L2 mode keeps ARP semantics; L3 mode does not. If your application relies on broadcast (DHCP client, mDNS, NetBIOS), L2 is the right pick. If you want clean per-IP isolation in a cloud VM, L3 is the right pick.
  • Children inherit the parent’s MAC. Switches see one MAC per port even with dozens of children. Good for cloud; bad if you need per-tenant L2 enforcement at the switch.
  • No host-comm restriction. Unlike MACVLAN, the host can ping its own children directly. This alone is why many engagements that started on MACVLAN migrate to IPVLAN.
  • Conntrack works fully in L3s mode. L2 and L3 modes skip some netfilter hooks for inter-child traffic; L3s applies the FORWARD chain. Pick L3s when you need iptables policy between children.
  • AWS source/destination check. If you run IPVLAN inside an EC2 instance and route extra prefixes through it, disable source/destination check on the ENI — otherwise traffic from children gets dropped at the VPC fabric.

In the engagements we run, IPVLAN L3 is the default for cloud-hosted hypervisors that need per-VM or per-pod IPs without paying for an overlay. MACVLAN is reserved for the few on-prem cases where applications rely on neighbour broadcast. The choice is captured in our Ansible role library and applied via the managed-operations practice during initial host bring-up.