Configure a bridge device for KVM in Linux

Source: Internet
Author: User

To install a Linux operating system with virtualization functions (CentOS is used as an example here), we generally have two methods:

1. Install the virtualization package or configure the virtualization package on the PXE Server during the CD installation.
2. Manually install virtualization components in a system without virtualization components installed


If the environment we build must use virtualization, or virtualization is one of the main purposes of building this environment, we will install all the virtualization components during system installation, to avoid Incomplete installation or some service dependencies in the future, the troubleshooting time is much higher than the time for installing several more packages.
After we have installed the virtualization component (RHEL6.0, the system comes with KVM and no XEN virtualization support is available), a bridge device such as virbr0 will be automatically generated.

[Root @ clovemzone ~] # Brctl show
Bridge name bridge id STP enabled interfaces
Virbr0 8000.5254007543ce yes virbr0-nic

According to this article: virbr0 uses the NAT method by default to communicate with the Virtual Machine Nic, in the actual production environment, in most cases, we use the Bridge method for communication between physical machines and virtual machines. The method for deleting this virbr0 has been described in the above link, this article mainly describes the simple implementation principle of Bridge and the actual configuration method.

RHEL6 KVM virtualization creates a bridge NIC-Bridge

RedHat Linux KVM Virtual Machine bridging

Installation/bridging settings of KVM in CentOS 5.6/virtual machine creation and operation

Assume that our physical machine has a wired network card that is displayed as eth0 in the system. We set it to br0, which is a bridge device.

The Bridge device we often call is actually a Bridge device, which is equivalent to a two-layer switch used to connect all machines in the same network segment, so our goal is to configure the network device eth0 to br0. At this time, br0 becomes a so-called switch device, and the eth0 of our physical machine is also connected to the above.

[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 NICs are connected to br0. In this case, check the devices connected to br0.
[Root @ clovemzone ~] # Brctl show
Bridge name bridge id STP enabled interfaces
Br0 8000.0025903afe42 no eth0
Vnet0
Vnet1

In order to give you a better understanding, you can perform simple analysis based on actual operations.

1. view the NIC device information of a physical machine, as 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
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 the bridging device br0

[Root @ master ~] # Rpm-q bridge-utils // check whether the bridge software is installed
Bridge-utils-1.2-9.el6.x86_64
[Root @ master ~] # Brctl show
Bridge name bridge id STP enabled interfaces
[Root @ master ~] #

In this case, no bridging device exists. You can manually add the device or add it to the file to take effect.
(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

Delete the IP address above eth0 and add the fixed IP address above br0
[Root @ master ~] # Ip addr del dev eth0 192.168.3.176/24 // Delete the ip address on eth0
[Root @ master ~] # Ifconfig br0 192.168.3.176/24 up // configure the IP address of br0 and start the device
[Root @ master ~] # Route add default gw 192.168.3.1 // re-join the default Gateway

 

Check whether the configuration takes effect
[Root @ master ~] # Route // view the 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 address information of 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
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
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 whether the connection to the same network segment is successful and check whether the nic ip address is correctly bound.
PING 192.168.3.1 (192.168.3.1) 56 (84) bytes of data.
64 bytes from 192.168.3.1: icmp_seq = 1 ttl = 255 time = 3.45 MS
64 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 bytes ed, 0% packet loss, time 2000 ms
Rtt min/avg/max/mdev = 3.457/3.832/4.208/0.380 MS
[Root @ master ~] # Ping 192.168.1.1-w2 // test whether the connection is successful for different network segments and determine whether the gateway is successfully added
PING 192.168.1.1 (192.168.1.1) 56 (84) bytes of data.
64 bytes from 192.168.1.1: icmp_seq = 1 ttl = 255 time = 2.38 MS
64 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 bytes ed, 0% packet loss, time 2000 ms
Rtt min/avg/max/mdev = 2.381/5.011/7.642/2.631 MS

The above is a manual configuration method through commands, but we all know that the configuration results of these commands cannot take effect after the server is restarted. To make all the configurations take effect permanently, we still need to configure through the configuration file, then restart the NIC device, let the system help us configure, and then it will take effect after the restart.
Through the manual configuration method above, you can clearly see the configuration process of a bridge device, which is not visible when you write it into the configuration file and then let the system help you configure it :), in this case, we will restore all the configurations and perform related automatic configuration through the configuration file.

  • 1
  • 2
  • Next Page

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.