virsh 网络设置_Qemu&KVM第二篇之(4)使用virsh配置VM 网络network 问题

本文介绍了如何使用virsh命令来管理虚拟机网络,包括获取VM的MAC地址,查看ARP表,结合shell命令查找IP地址,以及列出和管理虚拟网络的详细步骤。此外,还提到了bridge-utils包在创建和管理桥接设备中的作用,对于设置主机虚拟机网络至关重要。
摘要由CSDN通过智能技术生成

I’m installing avahi on each VM, so they will advertise their own addresses. However that’s not the only option available (especiall if you VM contains something different from Linux). So enter magical world of virsh options!

*) First you need to get MAC addresses of your VM’s NICs:[root@5844 ~]# virsh domiflist b2bua

Interface  Type       Source     Model       MAC

-------------------------------------------------------

vnet0      network    default    virtio      52:54:00:aa:bb:cc

vnet1      bridge     br1        virtio      52:54:00:dd:ee:ff

[root@5844 ~]#

*) Now let’s take a look at the ARP table

[root@5844 ~]# arp -e

Address                  HWtype  HWaddress           Flags Mask            Iface

xx.xx.xx.xx              ether   xx:xx:xx:xx:xx:xx   C                     br0

192.168.122.14           ether   52:54:00:xx:xx:xx   C                     virbr0

192.168.122.51           ether   52:54:00:aa:bb:cc   C                     virbr0

[root@5844 ~]#

*) Now let’s glue everything together (and adding a bit of shell/regex magic):[root@5844 ~]# for mac in `virsh domiflist b2bua |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

192.168.122.51

[root@5844 ~]#

auto lo

iface lo inet loopback

auto eth0

iface eth0 inet manual

auto br0

iface br0 inet dhcp

pre-up ip link add br0 type bridge

pre-up ip link set dev br0 address 02:0e:89:06:d9:0f

pre-up ip link set eth0 master br0

post-down ip link set eth0 nomaster

post-down ip link delete br0

bridge_stp off

bridge_fd 0

bridge_maxwait 0

Managing virtual networks

This section covers managing virtual networks with the virsh command. To list virtual networks:virsh net-list

This command generates output similar to:[root@domain ~]# virsh net-list

Name                 State      Autostart

-----------------------------------------

default              active     yes

vnet1             active     yes

vnet2             active     yes

To view network information for a specific virtual network:virsh net-dumpxml [vnet name]

This displays information about a specified virtual network in XML format:# virsh net-dumpxml vnet1

vnet1

98361b46-1581-acb7-1643-85a412626e70

Other virsh commands used in managing virtual networks are:virsh net-autostart [network name] — Autostart a network specified as [network name]

virsh net-create [XML file] — Generates and starts a new network using a preexisting XML file

virsh net-define [XML file] — Generates a new network from a preexisting XML file without starting it

virsh net-destroy [network name] — Destroy a network specified as [network name]

virsh net-name [network UUID] — Convert a specified [network UUID] to a network name

virsh net-uuid [network name — Convert a specified [network name] to a network UUID

virsh net-start [name of an inactive network] — Starts a previously undefined inactive network

virsh net-undefine [name of an inactive network] — Undefine an inactive network

补充:

bridge-utils

The bridge-utils package contains a utility needed to create and manage bridge devices. This is useful in setting up networks for a hosted virtual machine (VM).

http://www.linuxfromscratch.org/blfs/view/svn/basicnet/bridge-utils.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值