Skip to content

Instantly share code, notes, and snippets.

@dehai
Forked from tensorfields/virt-addr.sh
Created May 11, 2016 09:03
Show Gist options
  • Save dehai/9a25e5448f6d51f38600645ee82d2cb6 to your computer and use it in GitHub Desktop.
Save dehai/9a25e5448f6d51f38600645ee82d2cb6 to your computer and use it in GitHub Desktop.
Get a KVM guest's IP address
#!/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