Docker MacVLAN vs IPVLAN - A Practical Deep Dive into Advanced Networking

Docker MacVLAN vs IPVLAN - A Practical Deep Dive into Advanced Networking

- 5 mins

Introduction

Introduction

Quick recap of how Docker networking works by default (bridge, NAT, port binding). Problem statement: Containers can’t be directly reached with their own IPs. Solution: Advanced drivers — MacVLAN & IPVLAN.

1. Why Use MacVLAN or IPVLAN?

Containers act like first-class citizens on the network.

Benefits:


2. MacVLAN Explained

How It Works:

Setup Example:

#Network can be different based on your network scope
docker network create -d macvlan \
  --subnet=192.168.1.0/24 \
  --gateway=192.168.1.1 \
  -o parent=enp1s0 \
  macvlan_net

dockermac

Run container:

#Ip can be different based on your network scope
docker run -itd --network macvlan_net --ip 192.168.1.195 nginx

dockermac

dockermac

Appears on LAN as its own device.

Testing nginx webserver connection from any other device in same network. Note: I did not expose any port to host machine and I still can able to reach nginx

dockermac


3. IPVLAN Explained

Unlike MacVLAN, IPVLAN containers share the host’s MAC. Only IPs differ. 👉 Looks cleaner to the switch/router, no multiple MAC addresses to worry about.

IPVLAN Modes:

1. L2 Mode

Setup:

#Network can be different based on your network scope
docker network create -d ipvlan \
  --subnet=192.168.1.0/24 \
  --gateway=192.168.1.1 \
  -o parent=enp1s0 \
  ipvlan_l2

Containers reachable on LAN directly.

⚠️ Security tools may flag this as MAC spoofing since many IPs map to one MAC.

2. L3 Mode

Example:

#Network can be different based on your network scope
docker network create -d ipvlan \
  --subnet=10.10.0.0/24 \
  -o parent=enp1s0 \
  -o ipvlan_mode=l3 \
  ipvlan_l3

Requires adding a static route on your router/gateway. Great for segmentation & isolation.


4. MacVLAN vs IPVLAN: Quick Comparison

Feature MacVLAN IPVLAN L2 IPVLAN L3
MAC per container Unique MACs Shared with host Shared with host
Works without promiscuous mode ❌ No ✅ Yes ✅ Yes
Requires static routes ❌ No ❌ No ✅ Yes
LAN reachability (same subnet) ✅ Yes ✅ Yes ⚠️ Needs routes
Isolation / segmentation ➖ Moderate ➖ Moderate ✅ Strong (routed subnets)
Switch port-security friendly ❌ Can break (many MACs) ✅ Friendlier (one MAC) ✅ Friendlier (one MAC)
IDS/IPS false-positive risk ➖ Normal ⚠️ Many IPs → one MAC ⚠️ Many IPs → one MAC
Typical use case Legacy/LAN realism Simpler LAN access Routed/isolated networks

5. Choosing the Right One

Conclusion

MacVLAN and IPVLAN unlock powerful networking capabilities in Docker beyond the default bridge. They let containers integrate directly into existing networks or create isolated routing domains.

Like all advanced networking, the right choice depends on your environment:


Thanks for reading!

Guneycan Sanli

Guneycan Sanli

Guneycan Sanli

A person who like learning, music, travelling and sports.

comments powered by Disqus