Interview's MateDocker
Interview's Mate

Docker

Compose · Networking · Security · Ops

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
Docker topics
Lesson 69/ 160
04. Docker Networking

Macvlan & IPvlan Drivers (Assigning Physical LAN IPs to Containers)

Give containers real LAN IPs with macvlan/ipvlan when they must look like VMs on the network.

Advancedmacvlan · ipvlan3 quiz questions
Practice DevOps Q&A
In plain wordsDiagramTheoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

Use macvlan when legacy discovery or monitoring must see containers as LAN peers; use IPvlan to reduce MAC-table pressure when the network architecture allows it.

Think of it like…

Macvlan hands every container a separate shopfront sign on the same street; IPvlan gives them numbered counters behind one street sign.

Where you’ve seen it

In practice, docker network create -d macvlan --subnet=192.168.50.0/24 --gateway=192.168.50.1 -o parent=eth0.50 lan50 is the concrete move for this job: give containers real LAN IPs with macvlan/ipvlan when they must look like VMs on the network. The release is not accepted until ping a LAN service and use ip link plus ARP/neigh inspection on the parent host; document the host-to-container route test separately confirms the result.

Words you’ll hear

macvlan
The implementation control in docker network create -d macvlan --subnet=192.168.50.0/24 --gateway=192.168.50.1 -o parent=eth0.50 lan50 for give containers real LAN IPs with macvlan/ipvlan when they must look like VMs on the network.
ipvlan
The result to observe with ping a LAN service and use ip link plus ARP/neigh inspection on the parent host; document the host-to-container route test separately, rather than infer from a successful command alone.
LAN IPs
The production boundary exposed when making the macvlan range overlap DHCP, or assuming a container can reach the host over the parent interface by default.

Visual diagram

Loading interactive diagram

Theory & deep dive

macvlan control path

The concrete mechanism is docker network create -d macvlan --subnet=192.168.50.0/24 --gateway=192.168.50.1 -o parent=eth0.50 lan50. The observable result is ping a LAN service and use ip link plus ARP/neigh inspection on the parent host; document the host-to-container route test separately; if those disagree, inspect the runtime evidence before changing unrelated settings.

Give containers real LAN IPs with macvlan/ipvlan when they must look like VMs on the network. Keep macvlan, ipvlan and LAN IPs in the same deployment record so the intent and the observed state cannot drift apart.

Concrete macvlan setup

docker network create -d macvlan --subnet=192.168.50.0/24 --gateway=192.168.50.1 -o parent=eth0.50 lan50

Key takeaway: Prove ipvlan with ping a LAN service and use ip link plus ARP/neigh inspection on the parent host; document the host-to-container route test separately, not with command success alone.

LAN IPs failure boundary

Containers on macvlan cannot ordinarily reach the host parent address because of bridge-hairpin behavior, and an 802.1q/tagged network, DHCP server or switch MAC limit can invalidate the setup. IP addresses must not collide with LAN DHCP ranges. The narrow failure to design for is making the macvlan range overlap DHCP, or assuming a container can reach the host over the parent interface by default.

Accept this compromise explicitly: Macvlan maximizes L2 compatibility; IPvlan scales MAC usage better, but both couple containers to LAN topology and IP management. The controlled check-ping a LAN service and use ip link plus ARP/neigh inspection on the parent host; document the host-to-container route test separately-also identifies the point where a different design is safer.

Deliberate failure test

Exercise this failure safely: making the macvlan range overlap DHCP, or assuming a container can reach the host over the parent interface by default.

Key takeaway: Macvlan maximizes L2 compatibility; IPvlan scales MAC usage better, but both couple containers to LAN topology and IP management.

How it works, step by step

Step 1 of 4
Design

1. State the boundary

Write down why the workload needs this: Containers on macvlan cannot ordinarily reach the host parent address because of bridge-hairpin behavior, and an 802.1q/tagged network, DHCP server or switch MAC limit can invalidate the setup. IP addresses must not collide with LAN DHCP ranges.

Use macvlan when legacy discovery or monitoring must see containers as LAN peers; use IPvlan to reduce MAC-table pressure when the network architecture allows it.
Key numbers at this step
Intent
macvlan

When to use it & trade-offs

What it is

Macvlan gives each container a distinct MAC address on a physical network so it looks like another LAN device; IPvlan shares a parent MAC and can isolate by L2 or L3. Both require a parent interface, subnet/IPAM planning and host L2/L3 routing awareness.

Why it matters: Containers on macvlan cannot ordinarily reach the host parent address because of bridge-hairpin behavior, and an 802.1q/tagged network, DHCP server or switch MAC limit can invalidate the setup. IP addresses must not collide with LAN DHCP ranges.

When to reach for it

  • The fit is strongest for this job: give containers real LAN IPs with macvlan/ipvlan when they must look like VMs on the network. Pair it with ping a LAN service and use ip link plus ARP/neigh inspection on the parent host; document the host-to-container route test separately in the runbook.
  • Production macvlan changes should make ipvlan observable through docker network create -d macvlan --subnet=192.168.50.0/24 --gateway=192.168.50.1 -o parent=eth0.50 lan50, rather than trusting the runtime default.
  • Keep a rollback example for the case where making the macvlan range overlap DHCP, or assuming a container can reach the host over the parent interface by default.

When to avoid or be careful

  • Do not accept command success while the system can still fail by making the macvlan range overlap DHCP, or assuming a container can reach the host over the parent interface by default.
  • Avoid erasing LAN IPs protection merely to dodge this cost: “Macvlan maximizes L2 compatibility; IPvlan scales MAC usage better, but both couple containers to LAN topology and IP management”.
  • Do not replace the evidence path-ping a LAN service and use ip link plus ARP/neigh inspection on the parent host; document the host-to-container route test separately-with a screenshot or a mutable tag.

docker network create -d macvlan --subnet=192.168.50.0/24 --gateway=192.168.50.1 -o parent=eth0.50 lan50: practical choices

Explicit macvlan
Best for: Give containers real LAN IPs with macvlan/ipvlan when they must look like VMs on the network, with a reviewed runbook.

Strengths: Macvlan gives each container a distinct MAC address on a physical network so it looks like another LAN device; IPvlan shares a parent MAC and can isolate by L2 or L3. Both require a parent interface, subnet/IPAM planning and host L2/L3 routing awareness.

Watch out: Macvlan maximizes L2 compatibility; IPvlan scales MAC usage better, but both couple containers to LAN topology and IP management.

Ambient default
Best for: Short-lived ipvlan experiments with low blast radius.

Strengths: It can begin with docker network create -d macvlan --subnet=192.168.50.0/24 --gateway=192.168.50.1 -o parent=eth0.50 lan50 and fewer surrounding controls.

Watch out: It silently accepts making the macvlan range overlap DHCP, or assuming a container can reach the host over the parent interface by default, which makes the result hard to reproduce after promotion.

Managed LAN IPs
Best for: Teams that centralize LAN IPs policy across many workloads.

Strengths: Containers on macvlan cannot ordinarily reach the host parent address because of bridge-hairpin behavior, and an 802.1q/tagged network, DHCP server or switch MAC limit can invalidate the setup. IP addresses must not collide with LAN DHCP ranges.

Watch out: The platform adds an ownership and debugging layer; retain ping a LAN service and use ip link plus ARP/neigh inspection on the parent host; document the host-to-container route test separately as the direct check.

Interview signals & numbers to know

When this topic comes up

  • docker network create -d macvlan --subnet=192.168.50.0/24 --gateway=192.168.50.1 -o parent=eth0.50 lan50
  • ping a LAN service and use ip link plus ARP/neigh inspection on the parent host; document the host-to-container route test separately
  • Failure signature: making the macvlan range overlap DHCP, or assuming a container can reach the host over the parent interface by default
  • Trade-off: Macvlan maximizes L2 compatibility; IPvlan scales MAC usage better, but both couple containers to LAN topology and IP management.

Benchmarks & rules of thumb

1 parent interface -
required by the driver network
192.168.50.0/24 -
example container-only subnet
48-bit MAC -
macvlan allocates a visible one per endpoint

Common mistakes & follow-ups

Common interview mistakes

  • Treating a successful docker network create -d macvlan --subnet=192.168.50.0/24 --gateway=192.168.50.1 -o parent=eth0.50 lan50 as proof and skipping ping a LAN service and use ip link plus ARP/neigh inspection on the parent host; document the host-to-container route test separately.
  • Making the macvlan range overlap DHCP, or assuming a container can reach the host over the parent interface by default
  • Optimizing macvlan without accepting that macvlan maximizes L2 compatibility; IPvlan scales MAC usage better, but both couple containers to LAN topology and IP management.

Likely interviewer follow-ups

  • Why does docker network create -d macvlan --subnet=192.168.50.0/24 --gateway=192.168.50.1 -o parent=eth0.50 lan50 address macvlan here rather than through application code?
  • How would you distinguish healthy ipvlan from the failure “making the macvlan range overlap DHCP, or assuming a container can reach the host over the parent interface by default” using ping a LAN service and use ip link plus ARP/neigh inspection on the parent host; document the host-to-container route test separately?
  • When would this trade-off-“Macvlan maximizes L2 compatibility; IPvlan scales MAC usage better, but both couple containers to LAN topology and IP management”-justify a different LAN IPs design?
Interview tip: Give one concrete operation-docker network create -d macvlan --subnet=192.168.50.0/24 --gateway=192.168.50.1 -o parent=eth0.50 lan50-and one proof-ping a LAN service and use ip link plus ARP/neigh inspection on the parent host; document the host-to-container route test separately. Then name the boundary: making the macvlan range overlap DHCP, or assuming a container can reach the host over the parent interface by default.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply Macvlan & IPvlan Drivers (Assigning Physical LAN IPs to Containers) with generative AI interview Q&A and hands-on practice.

Open DevOps Q&A →Tech Learn Q&A
Previous topic
None Networking Mode (--network none) for Air-Gapped Workloads
Next topic
Overlay Networks for Multi-Host Container Communication