KVM中新建虚拟子网

1.vi/etc/libvirt/qemu/networks/qybr.xml

<network>

<name>qybr10</name>

<uuid>80eab63e-2b1e-4844-b237-0bb3288c39c3</uuid>

<forwardmode='nat'/>

<bridgename='qybr10'stp='on'delay='0'/>

<ipaddress='10.10.10.1'netmask='255.255.255.0'>

<dhcp>

<rangestart='10.10.10.2'end='10.10.10.254'/>

</dhcp>

</ip>

</network>

2.virshnet-define/etc/libvirt/qemu/networks/qybr10.xml

virshnet-autostartqybr10

virshnet-startqybr10

3.vi/etc/libvirt/qemu/QianYuSrvZTE_IVR.xml

<typearch='x86_64'machine='pc-0.12'>hvm</type>

<bootdev='hd'/>

</os>

<features>

<acpi/>

<apic/>

<pae/>

</features>

<clockoffset='localtime'/>

<on_poweroff>destroy</on_poweroff>

<on_reboot>restart</on_reboot>

<on_crash>restart</on_crash>

<devices>

<emulator>/usr/bin/kvm</emulator>

<disktype='file'device='disk'>

<drivername='qemu'type='raw'/>

<sourcefile='/var/lib/libvirt/images/QianYuSrvZTE_IVR.img'/>

//指定img文件位置

<targetdev='hda'bus='ide'/>

</disk>

<disktype='file'device='cdrom'>

<drivername='qemu'type='raw'/>

<sourcefile='/media/iso/zh-hans_windows_xp_professional_with_service_pack_3_x86_cd_vl_x14-74070.iso'/>

<targetdev='hdc'bus='ide'/>

<readonly/>

</disk>

<interfacetype='bridge'>

<macaddress='52:54:00:70:a2:e4'/>

<sourcebridge='qybr10'/>

</interface>

<consoletype='pty'>

<targetport='0'/>

</console>

<consoletype='pty'>

<targetport='0'/>

</console>

<inputtype='tablet'bus='usb'/>

<inputtype='mouse'bus='ps2'/>

<graphicstype='vnc'port='-1'autoport='yes'/>

<video>

<modeltype='cirrus'vram='9216'heads='1'/>

</video>

</devices>

</domain>

4.createanewVM:

virshdefine/etc/libvirt/qemu/QianYuSrvZTE_IVR.xml

virshstartQianYuSrvZTE_IVR

5.portforwarding:10180

iptables-tnat-IPREROUTING-ptcp--dport10180-jDNAT--to-destination10.10.10.xx:80

iptables-IFORWARD-mstate-d10.10.10.0/24--stateNEW,RELATED,ESTABLISHED-jACCEPT

注:子网建立完之后如何进行删除virshnet-destroy/etc/libvirt/qemu/networks/xxx

virshnet-undefine/etc/libvirt/qemu/networks/xxx

kvm

相关推荐