smoser's thoughts

A dumping ground for thoughts and writings by smoser.

Using network manager in an Ubuntu lxd container.

For one reason or another you may want to use NetworkManager inside a container. An lxd container of recent vintage Ubuntu release (18.04) will have cloud-init render networking through systemd-networkd.

I needed to play around with a vpn that expected NetworkManager to be running. Here is a simple recipe for setting up network manager to manage network in an LXD container.

Thats it. You should have functional nmcli now.

root@nm-test:~# nmcli
eth0: connected to Wired connection 1
        "eth0"
        ethernet (veth), 00:16:3E:63:BC:31, sw, mtu 1500
        ip4 default, ip6 default
        inet4 10.157.246.65/24
        route4 0.0.0.0/0
        route4 10.157.246.0/24
        inet6 fd42:54b0:2d39:df1:5394:5920:e551:94d9/64
        inet6 fe80::d670:4eee:34ec:2dd9/64
        route6 fd42:54b0:2d39:df1::/64
        route6 ::/0
        route6 ff00::/8
        route6 fe80::/64
        route6 fe80::/64

lo: unmanaged
        "lo"
        loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536

DNS configuration:
        servers: 10.157.246.1
        domains: lxd
        interface: eth0

        servers: fe80::fced:6bff:fe63:9e55 fd42:54b0:2d39:df1::1
        interface: eth0

It may be useful for you to rename the automatically generated ‘Wired Connection 1’ to something more friendly.

$ lxc exec nm-test -- nmcli conn modify 'Wired connection 1' connection.id eth0

Lastly, you may not get the a dhcp request by default. I’m not sure why, but I have seen that happen. To tell network-manager that you want one:

$ lxc exec nm-test -- nmcli conn modify eth0 ipv4.method auto