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.


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.

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

Leave a Reply

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

You are commenting using your 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.


%d bloggers like this: