Sungju's Slow Life

Personal journal


Check IP address of a virtual guest

There’s a time you want to check virtual guest’s IP, but no way to access the machine as you only have text terminal.

You can retrieve IP address by using the following script.

#!/bin/bash

macaddress=`virsh dumpxml $1 | grep "mac address" | awk 'BEGIN { FS = "=" }; {print $2}' | sed 's//>/ /'`
macaddress=`echo $macaddress | sed "s/'/ /g"`

ipaddr=`grep $macaddress /var/lib/libvirt/dnsmasq/default.leases | awk '{print $3}'`

echo VM $1 uses $ipaddr "($macaddress)"

It’s quite simple, but would be useful if you want to check it quickly.

http://pagead2.googlesyndication.com/pagead/show_ads.js

# ./extrace_vm_ip.sh Fedora-node1
VM Fedora-node1 uses 192.168.122.53 ( 52:54:00:13:3e:90 )


Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About Me

A software engineer who loves any technologies that makes life easier. That’s why I love Linux and Mac at the same time.

Newsletter

%d bloggers like this: