IP Address From QEMU Guest Agent

On a KVM host, it’s fairly easy to get a guest’s IP from the internal network to the host.

[jhooks@kvm2 ~]$ sudo virsh domifaddr Tower
 Name       MAC address          Protocol     Address
 vnet0      52:54:00:e7:01:55    ipv4

However if you you have the guest on a full bridge or macvtap interface you won’t see anything. To get that information you need to add the QEMU guest agent.

On CentOS it’s simply called qemu-guest-agent.

With this installed you can now query the guest’s address by passing --source agent:

[jhooks@kvm2 ~]$ sudo virsh domifaddr Tower --source agent
Name       MAC address          Protocol     Address
lo         00:00:00:00:00:00    ipv4
-          -                    ipv6         ::1/128
eth0       52:54:00:fc:77:18    ipv4
-          -                    ipv6         fe80::5054:ff:fefc:7718/64
vnet0      52:54:00:e7:01:55    ipv4

Dynamic DNS with Cloudflare

At home I use Ubiquiti gear for all of my networking and I use Cloudflare for my external DNS. Rather than use another service like DynDNS or No-IP, I set up a small script that runs on my EdgeRouter Lite that updates records for my stuff at home in a simple cron job. The script just uses Cloudflare’s API to update an existing record. I haven’t found a way to get the record name from the web interface yet so you do need to get the record ID from the API.


ip=$(ifconfig eth0 | grep "inet addr:" | cut -d: -f2 | awk '{ print $1 }')

curl -X PUT "https://api.cloudflare.com/client/v4/zones/$zoneID/dns_records/$recordID" \
     -H "X-Auth-Email: $email" \
     -H "X-Auth-Key: $key" \
     -H "Content-Type: application/json" \
     --data '{"type":"A","name":"'"$recordName"'","content":"'"$ip"'","ttl":120,"proxied":false}' -k

Another option rather than getting the IP from the interface is using icanhazip.com (thanks Major!) which will return a just your IP in a string. This way you don’t need to use your edge device to interface with Cloudflare, any internal system will work.