libvirt kvm_如何在Kvm / Libvirt中获取Runnig VM IP地址

libvirt kvm

libvirt kvm

There are times when we start virtual machine and want to get ip address quickly without open any GUI or connecting virtual machines console. Here is the tip.

有时,我们启动虚拟机并希望快速获取IP地址,而无需打开任何GUI或连接虚拟机控制台。 这里是提示。

virsh domiflist命令 (virsh domiflist Command)

#!/bin/bash 
VMNAME=$1 
for mac in `sudo virsh domiflist $VMNAME |grep -o -E "([0-9a-f]{2}:){5}([0-9a-f]{2})"` ; do arp -e | grep $mac  | grep -o -P "^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}" ; done

The magic is that virtual machines interfaces are listed than mac address is grepped. After grepping mac address we are looking our ARP table to find corresponding ip address and put it to the screen. This script will list all interfaces of VM if it has more than one.

神奇之处在于,列出了虚拟机接口,而不是grep了mac地址。 grep mac mac address之后,我们正在查看我们的ARP表以找到相应的IP地址并将其显示在屏幕上。 如果该脚本有多个,它将​​列出VM的所有接口。

As we have provided as script we can use this script like below. We will name script as vm_ip and provide the virtual machine or VM name as parameter. VM name is ubu1 in this example.

正如我们提供的脚本一样,我们可以像下面这样使用该脚本。 我们将脚本命名为vm_ip并提供虚拟机或VM名称作为参数。 在此示例中,虚拟机名称为ubu1。

$ ./vm_ip "ubu1"
LEARN MORE  What Is OSI (Open Systems Interconnection) Model?
了解更多什么是OSI(开放系统互连)模型?

翻译自: https://www.poftut.com/how-to-get-runnig-vm-ip-address-in-kvmlibvirt/

libvirt kvm

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值