Scenario:
You have created a macvlan network called mymacvlan to give containers their own MAC addresses on the physical network. However, containers mac1 and mac2 started on this network cannot ping the host or the gateway at 192.168.50.1.
Task:
Correct the macvlan network configuration creating mymac0 interface so that both mac1 and mac2 can successfully ping the gateway at 192.168.50.1 .
Note: host-side macvlan interface should be named mymac0
Step 1: Check current network configuration
docker network ls | grep mymacvlan
Verify the macvlan network exists.
Step 2: Inspect macvlan network details
docker network inspect mymacvlan
View subnet, gateway, and parent interface configuration.
Step 3: Check container status
docker ps | grep -E 'mac1|mac2'
Verify both containers are running.
Step 4: Check container network configuration
docker inspect mac1 --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'
docker inspect mac2 --format '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'
See what IPs the containers have.
Step 5: Test connectivity from containers (should fail)
docker exec mac1 ping -c1 192.168.50.1 2>&1 || echo "Ping failed as expected"
Observe the failure to reach gateway.
Step 6: Identify the parent interface
docker network inspect mymacvlan | grep parent
Find which physical interface the macvlan is using (e.g., eth0).
Step 7: Create a macvlan interface on the host
sudo ip link add mymac0 link enp1s0 type macvlan mode bridge
Create host-side macvlan interface using the same parent interface.
Step 8: Assign an IP to the host macvlan interface
sudo ip addr add 192.168.50.254/24 dev mymac0
Give the host interface an IP in the same subnet as containers.
Step 9: Bring the interface up
sudo ip link set mymac0 up
Activate the interface.
Step 10: Verify the interface is configured
ip addr show mymac0
Check the interface has the IP and is in UP state.
Step 11: Test connectivity from mac1
docker exec mac1 ping -c1 192.168.50.1
Should now succeed with the gateway reachable.
Step 12: Test connectivity from mac2
docker exec mac2 ping -c1 192.168.50.1
Verify second container can also reach the gateway.