Skip to content

Instantly share code, notes, and snippets.

@sudeeshjohn
Forked from tensorfields/virt-addr.sh
Created April 15, 2016 09:53
Show Gist options
  • Select an option

  • Save sudeeshjohn/797e8d95487abd2a03c3bcad28a424c9 to your computer and use it in GitHub Desktop.

Select an option

Save sudeeshjohn/797e8d95487abd2a03c3bcad28a424c9 to your computer and use it in GitHub Desktop.

Revisions

  1. David Palma created this gist Jan 3, 2013.
    14 changes: 14 additions & 0 deletions virt-addr.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    #!/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 }'
    }