###########Bridge方式使物理网段与VM在相同网段中###################
br0: Configure Bridging for eth0
Edit /etc/sysconfig/network-scripts/ifcfg-eth0, enter:
# vi /etc/sysconfig/network-scripts/ifcfg-eth0
Update it as follows:
DEVICE=eth0
3ONBOOT=yes
ETHTOOL_OPTS="autoneg off speed 100 duplex full"
BRIDGE=br0
HWADDR=b8:ac:6f:65:31:e5
Save and close the file. Create /etc/sysconfig/network-scripts/ifcfg-br0, enter:
# vi /etc/sysconfig/network-scripts/ifcfg-br0
Update it as follows (note options are case sensitive i.e. Bridge and bridge are two different options)
DEVICE=br0
TYPE=Bridge
BOOTPROTO=static
ONBOOT=yes
IPADDR=10.10.21.70
NETMASK=255.255.255.192
DELAY=0
Save and close the file. Finally, create static routing file /etc/sysconfig/network-scripts/route-br0, enter :
# vi /etc/sysconfig/network-scripts/route-br0
Edit it as follows:
10.0.0.0/8 via 10.10.21.122 dev br0
Save and close the file. Delete old /etc/sysconfig/network-scripts/route-eth0 (if exists):
# rm /etc/sysconfig/network-scripts/route-eth0
service network restart
############################################################################
NAT方式IP网络转换,将VM 192.168.1.0/24网段进行转换,使虚拟机能够上网,但外网无法访问虚拟机
参考文档:
http://segmentfault.com/blog/koy/1190000000644069
http://www.linuxidc.com/Linux/2012-05/61445.htm
[[email protected] networks]# cd /etc/libvirt/qemu/networks
[[email protected] networks]# scp default.xml mynat.xml
[[email protected] networks]# cat mynat.xml 修改mynat 网段至192.168.1.0/24
<network>
<name>mynat</name>
<uuid>504730bc-0a59-4fb7-a4a7-9b779fa4bf79</uuid>
<forward mode=‘nat‘/>
<bridge name=‘br0‘ stp=‘on‘ delay=‘0‘ />
<mac address=‘52:54:00:FD:BE:C8‘/>
<ip address=‘192.168.1.1‘ netmask=‘255.255.255.0‘>
<dhcp>
<range start=‘192.168.1.2‘ end=‘192.168.1.254‘ />
</dhcp>
</ip>
</network>
[[email protected] networks]# virsh net-define mynat.xml
Network mynat defined from mynat.xml
[[email protected] networks]# virsh net-autostart mynat
Network mynat marked as autostarted
[[email protected] networks]# virsh net-start mynat
[[email protected] networks]# brctl show
bridge name bridge id STP enabled interfaces
br0 8000.525400fdbec8 yes br0-nic
br1 8000.000000000000 no
pan0 8000.000000000000 no
virbr0 8000.525400fdbec9 yes virbr0-nic
[[email protected] networks]#