Lxd_add_macvlan_host script to enable a container to communicate with a LXD Host

Craig Miller has been using LXD for quite a while and he happens to be an extremely knowledgeable
Network engineer with especially significant expertise in IPv6.

LXD also support MACVLAN type of interface with eliminates the complexity of getting your container connected to a LAN, and then the Internet. However, there is a limitation, in that in the default config, the Linux Container can talk to the internet, but it can’t talk to the host it is residing on.

What lxd_add_macvlan_host.sh does

lxd_add_macvlan_host.sh` script solves this problem by creating an additional MACVLAN interface on the host, and adjusting routes so that the new interface is preferred.

This script is on Craig’s GITHUB…

1 Like

Yep this is a way to get around the no-host comms feature of macvlan.

what are advantages of macvlan over routed networking?

Hi Tom…

Yeah, I posted that because the script makes it much easier & less error prone for some LXD users to use rather than doing each step manually.

Also, I liked that he added several command line options to the script that are useful:

$ ./lxd_add_macvlan_host.sh -h
./lxd_add_macvlan_host.sh - creates MACVLAN interface on LXD Host
Example: $ ./lxd_add_macvlan_host.sh -a
-a Add MACVLAN interface
-4 Add MACVLAN IPv4 interface
-f Fix MACVLAN IPv4 route
-r Remove MACVLAN interface (see note below)
-i use this interface e.g. eth0

  • By Craig Miller - Version: 1.0*


Occasionally, the container may lose IPv4 connectivity to the LXD Host. For some reason, the preferred route to the MACVLAN network (inside the LXD Host) is removed.
In version 1.0 of the script was, added the parameter -f - to fix the IPv4 route.

After adding the host-shim interface with ./lxd_add_macvlan_host.sh -4, *it is possible at a later time to fix the IPv4 route with ./lxd_add_macvlan_host.sh -f. It is no longer necessary to remove and re-add the host-shim interface.
Also… this occurs only with IPv4, IPv6 does not have this problem.