Created
January 3, 2013 22:02
-
-
Save tensorfields/4447791 to your computer and use it in GitHub Desktop.
Get a KVM guest's IP address
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Returns the IP address of a running KVM guest VM | |
# Assumes a working KVM/libvirt environment | |
# | |
# Install: | |
# Add this bash function to your ~/.bashrc and `source ~/.bashrc`. | |
# Usage: | |
# $ virt-addr vm-name | |
# 192.0.2.16 | |
# | |
virt-addr() { | |
VM="$1" | |
arp -an | grep "`virsh dumpxml $VM | grep "mac address" | sed "s/.*'\(.*\)'.*/\1/g"`" | awk '{ gsub(/[\(\)]/,"",$2); print $2 }' | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@mistofvongola and the others.
If you have qmeu-agent installed on the guest machine you can user virsh to fetch the details directly from the VM using virsh.
Example commad:
virsh domifaddr Squid-4.1-CentOS-Testing --source agent --full
(the--source agent
flag is important)