virsh – show ip address of all running VMs

If you are using the libvirt and associated tools, then you must be aware about virt-manager. However this being a GUI tools, it is not possible to always use this. “virsh” is a good option for this.

To start with, if you need to know all the VMs all the running VMs, then you can use (to only view the names):

virsh list --name

Extending this to make it more useful is the case if you need to know the IP address for the running VMs. Here is a simple code that you can put in alias or function that can be used to get the IP address of the running VM’s.

virsh list --name | \
while read line 
do
      [[ ! -z $line ]] && virsh domifaddr $line
done

Bonus note:
If you want to start the VM, then you can use

virsh start

dnsmasq local name resolution with NetworkManager

Network Manager suports starting dnsmasq which helps you have a local cache for DNS thus getting faster resolution for the DNS queries.

Dnsmasq with netowrkmanager

So, one thing that I have been thinking about is having a local name resolution for the VMs. So, I wanted something like this to work:

vm1 => 172.17.42,1

vm2 => 172.17.42,2

and so on …

To achieve this and reverse dns to work, we will add the entries in file “/etc/NetworkManager/dnsmasq.d/hostnames“. Just one more problem, adding so many entries manually? So, to help you with that, I created this small script:

#!/bin/bash -
#===============================================================================
#
#          FILE: add-dnsmasq.sh
#
#         USAGE: ./add-dnsmasq.sh
#
#   DESCRIPTION:
#
#       OPTIONS: ---
#  REQUIREMENTS: ---
#          BUGS: ---
#         NOTES: ---
#        AUTHOR: Amit Agarwal (aka), 
#  ORGANIZATION: 
#      REVISION:  ---
#===============================================================================

IPPRE='172.17.42.'
for i in {1..250}
do
    echo "address=/vm$i/$IPPRE$i" >> /etc/NetworkManager/dnsmasq.d/hostnames
    echo "ptr-record=vm$i,$IPPRE$i" >> /etc/NetworkManager/dnsmasq.d/hostnames
done

Just run this script to add all the entries and restart dnsmasq by killing the already running instance. 🙂

docker search description truncated

When you search with “docker search”, you would notice that the description of the image is truncated. Sometimes you want to see full description, to do so, you can use –no-trunc option. So, for example you want to search for fedora images, you can use the following command:

docker search --no-trunc  fedora