I’m wrestling with having a container on a macvlan network and still being able to talk to the host.
General setup
Host OS Ubuntu 16.04
Docker version 17.09.1-ce, build 19e2cf6
LAN 192.168.47.0/24
Host IP 192.168.47.250 (standard Ubuntu br0 bridge)
Container IP 192.168.47.34
Older versions of the docker documentation for mavlan networks included following note:
When using macvlan, you cannot ping or communicate with the default namespace IP address. For example, if you create a container and try to ping the Docker host’s eth0, it will not work. That traffic is explicitly filtered by the kernel modules themselves to offer additional provider isolation and security.
A macvlan subinterface can be added to the Docker host, to allow traffic between the Docker host and containers. The IP address needs to be set on this subinterface and removed from the parent address. ip link add mac0 link $PARENTDEV type macvlan mode bridge
Your networking equipment needs to be able to handle “promiscuous mode”, where one physical interface can be assigned multiple MAC addresses.
Especially if you use a vm, you need to make sure to enable promiscous mode. Some hypervisors provide the settings on VM level, some on vSwitch level.
Here’s what I used. It is definitely not a good practice but it can solve issues in some cases.
ip link add mac0 link enoX type macvlan mode bridge
ip addr add 192.168.X.X/24 dev mac0
ip link set mac0 up
ip route add 192.168.X.0/24 dev mac0
ip route delete 192.168.X.0/24 dev enoX