KVM 虚拟机网卡桥接网络配置

KVM三种网络类型

[root@node124 opt]# virt-install --help| grep network

    --pxe               Boot from the network using thePXE protocol

    -w NETWORK,--network=NETWORK

                       Configure a guest network interface. Ex:

                        --networkbridge=mybr0

                       --network network=my_libvirt_virtual_net

                       --network network=mynet,model=virtio,mac=00:11...

   --nonetworks        Don't createnetwork interfaces for the guest.

 

 

虚拟机默认通过NAT方式桥接到virbr0

[root@node124 opt]# brctl show

bridge name     bridgeid                       STP enabled      interfaces

virbr0                8000.525400a30536       yes                   virbr0-nic

                                                                                    vnet0

[root@node124 opt]# ifconfig

virbr0    Linkencap:Ethernet  HWaddr52:54:00:A3:05:36                    #宿主机桥接的网卡

          inetaddr:192.168.122.1 Bcast:192.168.122.255 Mask:255.255.255.0

          UPBROADCAST RUNNING MULTICAST MTU:1500  Metric:1

          RX packets:44errors:0 dropped:0 overruns:0 frame:0

          TXpackets:14 errors:0 dropped:0 overruns:0 carrier:0

         collisions:0 txqueuelen:0

          RXbytes:3432 (3.3 KiB)  TX bytes:1435 (1.4KiB)

 

vnet0     Linkencap:Ethernet  HWaddr FE:54:00:37:E2:FA       #虚拟机主机的网卡// vnet0桥接到virbr0网桥的端口上

          inet6addr: fe80::fc54:ff:fe37:e2fa/64 Scope:Link

          UPBROADCAST RUNNING MULTICAST MTU:1500  Metric:1

          RXpackets:38 errors:0 dropped:0 overruns:0 frame:0

          TXpackets:1571 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:500

          RXbytes:3532 (3.4 KiB)  TX bytes:82555(80.6 KiB)

 

创建一个网桥并将物理网卡绑定到网桥上,在网桥上配置IP地址

创建一个新网桥:

[root@node124 opt]# brctl addbr br0

[root@node124 opt]# brctl show

bridge name     bridgeid                       STP enabled      interfaces

br0                   8000.000000000000       no                   

virbr0                8000.525400a30536       yes                   virbr0-nic

                                                                                    vnet0

将网桥桥接到宿主机的真实网卡上(关联真实物理网卡):

[root@node124 opt]# brctl addif br0 eth1

这时与eth1相连接的数据会断开,

 

将eth1的IP地址清除

#ip addr del dev eth1 192.168.2.124/16

将新创建的网桥配置一个跟eth1一样的IP地址:

#ifconfig br0 192.168.2.124/16 up

[root@node124 ~]# ifconfig

br0       Linkencap:Ethernet  HWaddr00:0C:29:C2:AD:BA 

          inetaddr:192.168.2.124 Bcast:192.168.255.255  Mask:255.255.0.0

          inet6addr: fe80::20c:29ff:fec2:adba/64 Scope:Link

          UPBROADCAST RUNNING MULTICAST MTU:1500  Metric:1

          RXpackets:77272 errors:0 dropped:0 overruns:0 frame:0

          TXpackets:46 errors:0 dropped:0 overruns:0 carrier:0

         collisions:0 txqueuelen:0

          RXbytes:3686961 (3.5 MiB)  TX bytes:7213(7.0 KiB)

 

eth1     Linkencap:Ethernet  HWaddr00:0C:29:C2:AD:BA 

          inet6addr: fe80::20c:29ff:fec2:adba/64 Scope:Link

          UPBROADCAST RUNNING MULTICAST MTU:1500  Metric:1

          RXpackets:9078175 errors:0 dropped:0 overruns:0 frame:0

          TXpackets:14618 errors:0 dropped:0 overruns:0 carrier:0

         collisions:0 txqueuelen:1000

          RXbytes:706370069 (673.6 MiB)  TXbytes:4984824 (4.7 MiB)

[root@node124 ~]# brctl show

bridge name     bridgeid                       STP enabled      interfaces

br0                   8000.000c29c2adba       no                    eth1

virbr0                8000.525400a30536       yes                   virbr0-nic

                                                                                    vnet0

将虚拟机的网络桥接到br0上面,直接通过eth1网卡上网(直接桥接上网)

先停止虚拟机:

[root@node124 ~]# virsh shutdown CentOS-6.7-x86_64

 

1.通过virsh 编辑xml文件

[root@node124 ~]# virsh edit CentOS-6.7-x86_64

Domain CentOS-6.7-x86_64 XML configuration edited.

 修改前:

     52     <interface type='network'>

     53       <mac address='52:54:00:37:e2:fa'/>

     54       <source network='default'/>

     55       <model type='virtio'/>

     56       <address type='pci' domain='0x0000'bus='0x00' slot='0x03' function='0x0'/>

     57     </interface>

修改后:

     52     <interface type='bridge'>

     53       <mac address='52:54:00:37:e2:fa'/>

     54       <source bridge='br0'/>

     55       <model type='virtio'/>

     56       <address type='pci' domain='0x0000'bus='0x00' slot='0x03' function='0x0'/>

     57     </interface>

修改完成后,重新启动虚拟机;

[root@node124 ~]# virsh start CentOS-6.7-x86_64

Domain CentOS-6.7-x86_64 started

查看桥接的网卡:

[root@node124 ~]# brctl show

bridge name     bridgeid                       STP enabled      interfaces

br0                   8000.000c29c2adba       no                    eth1

                                                                                    vnet0

virbr0                8000.525400a30536       yes                   virbr0-nic

 

通过以上操作,现在虚拟机就相当于vmware的桥接网络,可以配置192.168.2.0/16网段的IP地址,并且可以上网

桥接相当于直接接到交换机的端口上,直接级连交换机

 

 

分割线
感谢打赏
江西数库信息技术有限公司
YWSOS.COM 平台代运维解决方案
 评论
 发表评论
姓   名:

Powered by AKCMS