Best VPS Hosting | Website Hosting Pakistan | Domain & Hosting Services

Trying to configure a network bridge for KVM virtual machines? Here’s how we do it.

Here at Bobcares, we have seen several such KVM related queries as part of our Server Management Services for web hosts and online service providers.

Today we’ll take a look at configuring network bridge for KVM virtual machines.

 

Know more about KVM virtual machines

When a Linux bridge is used in KVM, it allows a virtual machine to access external networks and services outside of the virtual environment. Bridged networking is a dedicated network card to a virtual machine that provides a communication path to the outside networks. Also, this must be set up before creating a virtual machine using Virtual Manager.

Moreover, there are different ways to configure the Bridge Networking in Linux for use in KVM. By default, the Virtual Machine launched in KVM uses a NAT network.

Once you configure and use Bridged networking, guest operating systems access the external network connected directly to the host machine. Also, you can create a bridge either using Virtual Machine Manager, using virsh command-line tool, by directly editing network-scripts or using Linux Network management tools.

 

How to configure a network bridge for KVM virtual machines

Now let’s take a look at how to configure the network bridge.

 

Method 1: Creating Bridge Network using Virtual Machine Manager

Here are the steps to create a Linux bridge from Virtual Machine Manager (GUI). Make sure that you have installed KVM on your system.

1. Firstly, open Virtual Machine Manager, and go to Edit > Connection Details > Virtual Networks. Suppose the device name is virbr.
2. Next, click the + at the bottom of the window to configure a new network interface. Here, give the virtual network a name. For example, br1.
3. Then click the Forward button, in the next window, provide virtual network information.
4. After that, click forward and choose if to enable IPv6.
5. Now select the network type and forwarding policy.
6. Finish the setting and save the configurations. As a result, the new Virtual network must display on the overview page.
7. Finally, a bridge on the host system is automatically created for the network.

$ brctl show virbr
bridge name bridge id STP enabled interfaces
virbr 8000.525400c2410a yes virbr-nic

 

Method 2: Create KVM bridge with virsh command

First, create a new bridge XML file.

$ vim br1.xml

Then add the below details in the file.

<network>
<name>br10</name>
<forward mode=’nat’>
<nat>
<port start=’1024′ end=’65535’/>
</nat>
</forward>
<bridge name=’br10′ stp=’on’ delay=’0’/>
<ip address=’192.168.30.1′ netmask=’255.255.255.0′>
<dhcp>
<range start=’192.168.30.50′ end=’192.168.30.200’/>
</dhcp>
</ip>
</network>

To define a network from an XML file without starting it. So run the below command.

$ sudo virsh net-define br1.xml
Network br1 defined from br1.xml

To start a (previously defined) inactive network, run the below command.

$ sudo virsh net-start br1
Network br1 started

To set network to autostart at service start, run the below command.

$ sudo virsh net-autostart br1
Network br1 marked as autostarted

Then, confirm if the autostart flag is turned to yes. In the result, the Persistent should read yes as well.

$ sudo virsh net-list –all

Also, make sure to confirm bridge creation and IP address.

$ ip addr show dev br1

 

Method 3: Create a bridge by editing network-scripts (CentOS/RHEL/Fedora)

Here is a script that creates a bridge called br1.

$ sudo vim /etc/sysconfig/network-scripts/ifcfg-br1

With:

DEVICE=br1
STP=no
TYPE=Bridge
BOOTPROTO=none
DEFROUTE=yes
NAME=br1
ONBOOT=yes
DNS1=8.8.8.8
DNS2=192.168.30.1
IPADDR=192.xxx.xx.x
PREFIX=24
GATEWAY=192.xxx.xx.x

Here is the configuration of eth0 interface to which br1 will be bridged:

$ cat /etc/sysconfig/network-scripts/ifcfg-eno1
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
BRIDGE=br1

Finally, restart the network daemon.

$ sudo systemctl disable NetworkManager && sudo systemctl stop NetworkManager
$ sudo systemctl restart network.service

 

Method 4: Create a bridge by editing network-scripts (Debian/Ubuntu)

To configure the bridging interface, run the below command.

$ sudo vim /etc/network/interfaces
auto br1
iface br1 inet static
address 192.xxx.xx.xx
network 192.xxx.x.x
netmask 255.255.255.0
broadcast 192.xxx.x.xxx
gateway 192.xxx.x.x
dns-nameservers 192.xxx.x.x
bridge_ports eth0
bridge_stp off

Then disable all the lines on eth0 interface section so that it looks something like below:

auto eth0
iface eth0 inet manual

Finally, restart the networking service.

$ sudo systemctl restart networking.service

[Need any further assistance with KVM queries? – We’re available to help you]

 

Conclusion

Today, we saw how to configure a network bridge for KVM virtual machines.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

var google_conversion_label = “owonCMyG5nEQ0aD71QM”;



Source link

Author

Write A Comment