qemu-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

How to get the hostname and IP address of a VM using qemu-guest-agent


From: Ahmad Ismail
Subject: How to get the hostname and IP address of a VM using qemu-guest-agent
Date: Mon, 24 Jan 2022 00:06:05 +0600

I am running a VM using

qemu-system-x86_64 -accel kvm,thread=multi -cpu host -smp 1 -m 2048 \
-drive file=ubuntu-server1.qcow2,if=virtio -vga virtio -display none -daemonize \
-nic bridge,model=virtio-net-pci,mac=DE:AD:BE:EF:E0:00

To get the IP address I have to use:

ps -ef | grep qemu
arp | grep -i DE:AD:BE:EF:38:C4
ip neigh | grep -i DE:AD:BE:EF:38:C4

After, reading the wiki, I have installed and enabled qemu-guest-agent in the guest.

sudo apt install qemu-guest-agent
sudo systemctl start qemu-guest-agent
sudo systemctl enable qemu-guest-agent

I have run the VM using

qemu-system-x86_64 -accel kvm,thread=multi -cpu host -smp 1 -m 2048 \
-drive file=ubuntu-server1.qcow2,if=virtio -vga virtio -display none -daemonize \
-nic bridge,model=virtio-net-pci,mac=DE:AD:BE:EF:E0:00 \
-chardev socket,path=/tmp/qga.sock,server,nowait,id=qga0 \
-device virtio-serial \
-device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0

So, the socket is in /tmp/qga.sock.

Now I am not understanding how to use this socket to get the hostname and IP of the guest.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]