Page tree

Welcome to FreeSoftwareServers Confluence Wiki

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 2 Current »

 

I have my KVM guests on br0 interface so I think its a bit different, but here is my two scripts I made.

 

Note to use ARP you first need to have the MAC in your Arp Table. Therefor its best to use fping to do a quick ping of entire network (takes like 2 seconds). This makes sure your Arp cache is up to date.

apt-get install fping
yum install fping

 

Find a single guest IP via :

cat << 'EOF' > ~/findip.sh
#!/bin/bash
#FreeSoftwareServers.com

echo "Finding All Active IP's in Network via single Ping"
sleep 2s

fping -a -g 192.168.1.0/24
#nmap -sn 192.168.1.0/24

echo "Please Enter the Exact Name of the VM Guest:"

read guestname

arp -na | awk -v mac=$(virsh domiflist $guestname | awk '$2=="bridge"{print $NF}') '$0 ~ " at " mac {gsub("[()]", "", $2); print $2}'
EOF
chmod +x ~/findip.sh
sudo sh -c 'echo "alias findguestip=~/findip.sh" >> ~/.bashrc'
source ~/.bashrc
findguestip

Find All Guest IP's via:

cat << 'EOF' > ~/findallips.sh
#!/bin/bash
#FreeSoftwareServers.com

echo "Finding All Active IP's in Network via single Ping"
sleep 2s

fping -a -g 192.168.1.0/24
#nmap -sn 192.168.1.0/24

domainlog=/tmp/domain.log

virsh list --all | grep running |  cut -c 8- >> "$domainlog"

sed -i 's/running*//g' "$domainlog"

readarray domain < "$domainlog"

for i in "${domain[@]}"
do
ip="$(arp -na | awk -v mac=$(virsh domiflist $i | awk '$2=="bridge"{print $NF}') '$0 ~ " at " mac {gsub("[()]", "", $2); print $2}')"
echo "Hostname : $i IP : $ip"
done
rm "$domainlog"
EOF
chmod +x ~/findallips.sh
sudo sh -c 'echo "alias findallips=~/findallips.sh" >> ~/.bashrc'
source ~/.bashrc
findallips

https://unix.stackexchange.com/questions/425028/libvirt-kvm-how-to-get-the-ip-address-of-virtual-machines-on-a-bridged-netwo#

  • No labels