Thank the Party ~ Thank the original author's contribution. This article is from: http://www.linuxidc.com/Linux/2013-08/88719p2.htm This article can be used as the "KVM Virtual Machine Network Configuration Bridge mode, Nat Way" http://blog.csdn.net/ A supplement to hzhsan/article/details/44098537.
a bridge device for KVM configuration under Linux
In the case of installing a Linux operating system with virtualization features (take CentOS here for example), there are generally two ways:
1. Install the virtualization package at the time of the CD installation or configure the virtualization package on the PXE server
2. Manually install the virtualization component in a system that does not have a virtualization component installed
If we have to build an environment that must use virtualization, or virtualization is one of the main purposes of our set up the environment, then we install the system all the virtualization components all installed, to avoid late installation or some of the service dependencies are not resolved well, This is much more time-consuming than installing more than a few packages.
After we install the virtualization component (RHEL6.0, the system comes with KVM and no Xen virtualization support), it automatically generates a bridging device such as Virbr0
[Root@clovemzone ~]# Brctl Show
Bridge name Bridge ID STP enabled interfaces
Virbr0 8000.5254007543ce Yes Virbr0-nic
According to this article: http://www.linuxidc.com/Linux/2013-08/88720.htm, Virbr0 is using NAT to communicate with the virtual machine network card by default. In the actual production environment in most of our cases, the use of bridging bridge to the physical machine and virtual machine communication, delete this virbr0 method in the above given the link has been explained, this article mainly describes the simple implementation of bridges and the actual configuration method.
Related reading:
RHEL6 KVM Virtualization Create bridging network card-bridge http://www.linuxidc.com/Linux/2013-08/88517.htm
RedHat Linux KVM Virtual machine bridging http://www.linuxidc.com/Linux/2013-02/79934.htm
CentOS 5.6 KVM Installation/bridging setup/virtual machine creation and Operation Http://www.linuxidc.com/Linux/2012-12/76883.htm
Let's say we have a wired network card on our physical machine, which is displayed as eth0 in the system, and we build it up to a bridging device br0
We often say that bridge equipment is in fact the network bridges equipment, is equivalent to the two-tier switch to connect the same network segment of all the machines, so our goal is to configure the network equipment eth0 into BR0, at this time Br0 became the so-called switch equipment, The eth0 of our physical machine is also connected to the top.
[Root@clovemzone ~]# Brctl Show
Bridge name Bridge ID STP enabled interfaces
Br0 8000.0025903afe42 No eth0
After we create two virtual machines, all the virtual machine network cards are connected to br0, at this time, view the devices connected above br0
[Root@clovemzone ~]# Brctl Show
Bridge name Bridge ID STP enabled interfaces
Br0 8000.0025903afe42 No eth0
Vnet0
Vnet1
In order to let you understand more thoroughly, you can use the following diagram and combined with the actual operation of the simple analysis
1. View the physical Machine network card device information shown in Figure 1
[Root@master ~]# IP addr Show
1:lo: <LOOPBACK,UP,LOWER_UP> MTU 16436 qdisc noqueue State UNKNOWN
Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00
inet 127.0.0.1/8 Scope host Lo
INET6:: 1/128 Scope Host
Valid_lft Forever Preferred_lft Forever
2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU 1500 Qdisc pfifo_fast State up Qlen 1000
Link/ether 52:54:00:a7:b7:56 BRD FF:FF:FF:FF:FF:FF
inet 192.168.3.176/24 BRD 192.168.3.255 Scope Global eth0
Inet6 FE80::5054:FF:FEA7:B756/64 Scope link
Valid_lft Forever Preferred_lft Forever
2. Configure Bridging Equipment Br0
[Root@master ~]# rpm-q bridge-utils//See if bridging software is installed
Bridge-utils-1.2-9.el6.x86_64
[Root@master ~]# Brctl Show
Bridge name Bridge ID STP enabled interfaces
[Root@master ~]#
There are no bridging devices at this time, we can add them manually or add them to the file.
(1) Manually add
[Root@master ~]# brctl ADDBR br0
[Root@master ~]# Brctl Show
Bridge name Bridge ID STP enabled interfaces
Br0 8000.000000000000 No
[Root@master ~]# brctl addif br0 eth0
[Root@master ~]# Brctl Show
Bridge name Bridge ID STP enabled interfaces
Br0 8000.000000000000 No eth0
Remove the IP address above eth0 and add br0 to the above fixed IP address
[Root@master ~]# ip addr del dev eth0 192.168.3.176/24//delete IP address on eth0
[Root@master ~]# ifconfig br0 192.168.3.176/24 up//configure BR0 IP address and boot device
[Root@master ~]# route add default GW 192.168.3.1//rejoin defaults gateway
To see if the configuration is effective
[Root@master ~]# route//view default gateway
Kernel IP Routing Table
Destination Gateway genmask Flags Metric Ref use Iface
192.168.3.0 * 255.255.255.0 U 0 0 0 br0
Default 192.168.3.1 0.0.0.0 UG 0 0 0 br0
[Root@master ~]# IP Addr Show//view IP information for eth0 and BR0
1:lo: <LOOPBACK,UP,LOWER_UP> MTU 16436 qdisc noqueue State UNKNOWN
Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00
inet 127.0.0.1/8 Scope host Lo
INET6:: 1/128 Scope Host
Valid_lft Forever Preferred_lft Forever
2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU 1500 Qdisc pfifo_fast State up Qlen 1000
Link/ether 52:54:00:a7:b7:56 BRD FF:FF:FF:FF:FF:FF
Inet6 FE80::5054:FF:FEA7:B756/64 Scope link
Valid_lft Forever Preferred_lft Forever
3:BR0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU 1500 Qdisc noqueue State UNKNOWN
Link/ether 52:54:00:a7:b7:56 BRD FF:FF:FF:FF:FF:FF
inet 192.168.3.176/24 BRD 192.168.3.255 Scope Global BR0
Inet6 FE80::5054:FF:FEA7:B756/64 Scope link
Valid_lft Forever Preferred_lft Forever
[Root@master ~]# Ping 192.168.3.1-w2//test the success of the same network segment connection to determine if the NIC IP is properly bound
PING 192.168.3.1 (192.168.3.1) bytes of data.
Bytes from 192.168.3.1:icmp_seq=1 ttl=255 time=3.45 ms
Bytes from 192.168.3.1:icmp_seq=2 ttl=255 time=4.20 ms
---192.168.3.1 ping statistics---
2 packets transmitted, 2 received, 0% packet loss, time 2000ms
RTT Min/avg/max/mdev = 3.457/3.832/4.208/0.380 ms
[Root@master ~]# Ping 192.168.1.1-w2//test the success of different network segment connections to determine if the gateway was added successfully
PING 192.168.1.1 (192.168.1.1) bytes of data.
Bytes from 192.168.1.1:icmp_seq=1 ttl=255 time=2.38 ms
Bytes from 192.168.1.1:icmp_seq=2 ttl=255 time=7.64 ms
---192.168.1.1 ping statistics---
2 packets transmitted, 2 received, 0% packet loss, time 2000ms
RTT Min/avg/max/mdev = 2.381/5.011/7.642/2.631 ms
The above is a manual configuration method through the command, however, we all know that the results of these command configuration can not be effective after the server reboot, to make all the configuration permanent, we still need to configure through the configuration file, and then restart the network card device, so that the system to help us configure, and then restart is also in effect.
By using the manual configuration method above, you can clearly see a bridge equipment configuration process, which you write to the configuration file, and then let the system to help you configure the time is not visible:), then we will all the configuration restore, through the configuration file for the relevant automated configuration.
Restore Original Configuration
[root@master ~]# route Delete default//delete defaults gateway
[Root@master ~]# Route-n
Kernel IP Routing Table
Destination Gateway genmask Flags Metric Ref use Iface
192.168.3.0 0.0.0.0 255.255.255.0 U 0 0 0 br0
[Root@master ~]# Brctl Show
Bridge name Bridge ID STP enabled interfaces
Br0 8000.525400a7b756 No eth0
[Root@master ~]# brctl delif br0 eth0//Disconnect/delete br0 device on eth0
[Root@master ~] #ifconfig br0 down//Let BR0 equipment stop activity
[Root@master ~] #brctl delbr br0//delete br0
Root@master ~]# brctl Show//See if BR0 still exist
Bridge name Bridge ID STP enabled interfaces
[Root@master ~]# ifconfig eth0 192.168.3.176/24//re-assigning IP addresses to eth0
Root@master ~]# route Add default GW 192.168.3.1//rejoin defaults gateway
1234567891011 [root@master ~]# IP addr Show
1:lo: <LOOPBACK,UP,LOWER_UP> MTU 16436 qdisc noqueue State UNKNOWN
Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00
inet 127.0.0.1/8 Scope host Lo
INET6:: 1/128 Scope Host
Valid_lft Forever Preferred_lft Forever
2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU 1500 Qdisc pfifo_fast State up Qlen 1000
Link/ether 52:54:00:a7:b7:56 BRD FF:FF:FF:FF:FF:FF
inet 192.168.3.176/24 BRD 192.168.3.255 Scope Global eth0
Inet6 FE80::5054:FF:FEA7:B756/64 Scope link
Valid_lft Forever Preferred_lft Forever
--------------------------------------------------------------------------------
(2) Configuring bridging devices through configuration files
Configuration file please back up yourself
[Root@master ~]# Cat/etc/sysconfig/network-scripts/ifcfg-eth0
Device=eth0
Type=ethernet
Onboot=yes
Bridge=br0
[Root@master ~]# Cat/etc/sysconfig/network-scripts/ifcfg-br0
Device=br0
Type=bridge
Onboot=yes
Bootproto=static
ipaddr=192.168.3.176
netmask=255.255.255.0
gateway=192.168.3.1
Parameter detailed:
Ifcfg-eth0
DEVICE Specifies the NIC device name
Type specifies that the NIC is of an Ethernet card
Onboot Specify whether the NIC is powered on or not, remember to set to Yes
BRIDGE specifies the bridging device, which is specified here as a br0 device
Recommendation: The above variables (not variable values) are all uppercase.
Ifcfg-br0
DEVICE Specifies the NIC device name
Type specifies that the network adapter is a bridge
Onboot Specify whether the NIC is powered on or not, remember to set to Yes
BOOTPROTO Specifies how the NIC starts to obtain an IP address, setting the static
IPADDR set the IP address of the BR0 binding
NETMASK Set Subnet mask address
Gateway Settings Gateways
Recommendation: The variable value of the type variable is capitalized with the first letter, and the remaining letters are lowercase, such as Ethernet,bridge
Restart Network Service after configuration is complete
If you are worried about interference, we suggest to stop NetworkManager service, this service is very annoying
[Root@master ~]# service NetworkManager stop
[Root@master ~] #chkconfig NetworkManager off
[Root@master ~]# Service Network restart
[Root@master ~]# IP addr Show
1:lo: <LOOPBACK,UP,LOWER_UP> MTU 16436 qdisc noqueue State UNKNOWN
Link/loopback 00:00:00:00:00:00 BRD 00:00:00:00:00:00
inet 127.0.0.1/8 Scope host Lo
INET6:: 1/128 Scope Host
Valid_lft Forever Preferred_lft Forever
2:eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU 1500 Qdisc pfifo_fast State up Qlen 1000
Link/ether 52:54:00:a7:b7:56 BRD FF:FF:FF:FF:FF:FF
4:BR0: <BROADCAST,MULTICAST,UP,LOWER_UP> MTU 1500 Qdisc noqueue State UNKNOWN
Link/ether 52:54:00:a7:b7:56 BRD FF:FF:FF:FF:FF:FF
inet 192.168.3.176/24 BRD 192.168.3.255 Scope Global BR0
Inet6 FE80::5054:FF:FEA7:B756/64 Scope link
Valid_lft Forever Preferred_lft Forever
View bridging device information
[root@master ~]# brctl show
Bridge name Bridge id STP enabled int ERFACES&NBSP
br0 8000.525400a7b756 no eth0 < br> [Root@master ~]# route
Kernel IP routing table
destination gateway &NBSP ; genmask Flags Metric ref use iface
192.168.3.0 *&nbs P 255.255.255.0 u 0 0 & nbsp 0 br0
link-local * 255.255.0.0 u 1004 0 0 br0
default 192.168.3.1&NBSP ; 0.0.0.0 ug 0 0 0 br0
As a result, bridge equipment Br0 has been configured successfully, when the virtual machine to create the choice of virtual network interface when choosing BR0 can
To begin installing the virtual machine, view the NIC connection above the bridging device BR0:
[Root@master ~]# Brctl Show
Bridge name Bridge ID STP enabled interfaces
Br0 8000.0025903afe42 No eth0
Vnet0
--------------------------------------------------------------------------------
I wish you all a success.