Lxc list not showing virtual-machine ip with macvlan

Had a blast the last days learning more Linux stuff again and using LXD, just want to say thanks for this amazing tool!

Back to the topic, it might be probably because i am using a macvlan profile to pass a secondary IP from hetzner to the virtual-machine.

    $ lxc list
+-----------+---------+-------------------+------+-----------------+-----------+
|   NAME    |  STATE  |       IPV4        | IPV6 |      TYPE       | SNAPSHOTS |
+-----------+---------+-------------------+------+-----------------+-----------+
| cloud     | RUNNING | 10.0.0.145 (eth0) |      | CONTAINER       | 0         |
+-----------+---------+-------------------+------+-----------------+-----------+
| haproxy   | RUNNING | 10.0.0.66 (eth0)  |      | CONTAINER       | 0         |
+-----------+---------+-------------------+------+-----------------+-----------+
| ispconfig | RUNNING |                   |      | VIRTUAL-MACHINE | 0         |
+-----------+---------+-------------------+------+-----------------+-----------+
| xenforo   | RUNNING | 10.0.0.188 (eth0) |      | CONTAINER       | 0         |
+-----------+---------+-------------------+------+-----------------+-----------+

Hi!

With macvlan, your container/VM asks directly your provider (i.e. Hetzner) for a network configuration through DHCP. You will need to look into Hetzner’s requirements to assigning additional IP addresses to a cloud server. I have seen several posts about Hetzner here, therefore you can have a look at the older posts. For example, you may have to register the MAC address of the LXD VM somewhere at the management screen at Hetzner. Or, you may have to setup the IP addresses manually.

Not sure if you misunderstood me, i do have a working network. LXD just doesnt list the IP for the vm.

One year ago when i found LXD i run a container on a additional hetzner IP with macvlan and i can still see the public IP being listed in lxc list output.
The only difference iirc, was that back then i set the hwadrr via lxc config set for the container and today via this macvlan profile.

config: {}
description: macvlan for ISPconfig
devices:
  eth0:
    hwaddr: 00:44:22:33:1F:4F
    name: eth0
    nictype: macvlan
    parent: enp2s0
    type: nic
  root:
    path: /
    pool: default
    type: disk
name: mail
used_by:

So, since i can see the second public macvlan IP on my previous bare metal bionic container setup and i cannot see it now on a new bionic bare metal setup with the only difference being that it is a vm i thought i post this.

Previous macvlan profile:

    config: {}
    description: ""
    devices:
      eth0:
        nictype: macvlan
        parent: br0
        type: nic
    name: macvlan
    used_by:

LXD would learn the IP address of the macvlan-VM through LXD Agent.
Can you verify that it is installed?

$ locate lxd-agent                                                             
/snap/lxd/14442/bin/lxd-agent                                                        
/snap/lxd/14503/bin/lxd-agent

$ systemctl |grep lxd                                                      
run-snapd-ns-lxd.mnt.mount    loaded active mounted   /run/snapd/ns/lxd.mnt
snap-lxd-14442.mount          loaded active mounted   Mount unit for lxd, revision 14442
snap-lxd-14503.mount          loaded active mounted   Mount unit for lxd, revision 14503
snap.lxd.daemon.unix.socket   loaded active listening Socket unix for snap application lxd.daemon

$ which lxd                                                       
/snap/bin/lxd 

$ lxd --version
4.0.0

Need anything else?

In a LXD VM, the LXD agent is installed in each VM and is setup to run through systemd.
Currently, this is not performed automatically for you, and it is something that the container image will be doing in the near future.
For now, you need to get a shell into the LXD VM, and run:

ubuntu@vm1:~$ sudo -i
root@vm1:~# mount -t 9p config /mnt/
root@vm1:~# cd /mnt/
root@vm1:/mnt# ls -l
total 6390
-r-------- 1 999 root      745 Jan 24 09:18 agent.crt
-r-------- 1 999 root      288 Jan 24 09:18 agent.key
dr-x------ 2 999 root        5 Jan 24 09:18 cloud-init
-rwx------ 1 999 root      595 Jan 24 09:18 install.sh
-r-x------ 1 999 root 11495360 Jan 24 09:18 lxd-agent
-r-------- 1 999 root      713 Jan 24 09:18 server.crt
dr-x------ 2 999 root        4 Jan 24 09:18 systemd
root@vm1:/mnt# ./install.sh 
Created symlink /etc/systemd/system/multi-user.target.wants/lxd-agent.service → /lib/systemd/system/lxd-agent.service.
Created symlink /etc/systemd/system/multi-user.target.wants/lxd-agent-9p.service → /lib/systemd/system/lxd-agent-9p.service.

LXD agent has been installed, reboot to confirm setup.
To start it now, unmount this filesystem and run: systemctl start lxd-agent-9p lxd-agent
root@vm1:/mnt# reboot

More at https://blog.simos.info/how-to-use-virtual-machines-in-lxd/

Here is an example,

$ lxc launch ubuntu:18.04 vm1 --vm --profile default --profile macvlan --profile vm
$ lxc console vm1      # enable the LXD agent
$ lxc list
+------+---------+----------------------+------+-----------------+-----------+
| NAME |  STATE  |         IPV4         | IPV6 |      TYPE       | SNAPSHOTS |
+------+---------+----------------------+------+-----------------+-----------+
| vm1  | RUNNING | 192.168.1.9 (enp5s0) |      | VIRTUAL-MACHINE | 0         |
+------+---------+----------------------+------+-----------------+-----------+
$ 
1 Like

Thanks, worked like a charm!

We do plan on the lxd-agent units being available automatically in the Ubuntu cloud images in the future (we are going through the process now).

However for now you can either use the approach that @simos suggested here or use the ubuntu images generated by the LXD project:

E.g.

lxc launch images:ubuntu/bionic v1 --vm

i went with lxc launch 9e90b7b9ccdd v1 --vm

+-------+--------------+--------+---------------------------------------------+--------------+-----------------+----------+------------------------------+
| ALIAS | FINGERPRINT  | PUBLIC |                 DESCRIPTION                 | ARCHITECTURE |      TYPE       |   SIZE   |         UPLOAD DATE          |
+-------+--------------+--------+---------------------------------------------+--------------+-----------------+----------+------------------------------+
|       | 9e90b7b9ccdd | no     | ubuntu 18.04 LTS amd64 (release) (20200407) | x86_64       | VIRTUAL-MACHINE | 329.38MB | Apr 11, 2020 at 6:20pm (UTC) |
+-------+--------------+--------+---------------------------------------------+--------------+-----------------+----------+------------------------------+

How does one determine which is generated by the LXD project?

That is an ubuntu cloud image, created using:

lxc init ubuntu:18.04 v1 --vm

So that does not currently have the lxd-agent configured by default.

The LXD images have the name format like Ubuntu bionic amd64 rather than ubuntu 18.04 LTS amd64 (release):

lxc image show 4a56d369aab1
auto_update: true
properties:
  architecture: amd64
  description: Ubuntu bionic amd64 (20200402_08:37)
1 Like