Thursday 9 May 2013

Configuration of Bridge Network on Ethernet Card in Debian using XEN


Configuration of Bridge Network on Ethernet Card in Debian using XEN

Introduction:-

Bridging your network connection is a handy method for sharing your internet connection between two (or more) computers. It’s useful if you can’t buy a router with more than one Ethernet port, or if you’re a college student in a dorm room with limited Ethernet jacks and no router.

Basically, bridging is plugging one computer into another computer that already has a connection to a larger network (like the internet) and letting the bridged computer use the networked computer’s connection. To do so though, the networked computer needs to have two Ethernet ports, one for the big network, and one for the bridged computer. Make sure that before starting that the computer you’re going bridge through has two Ethernet ports, and that the hardware is capable of bridging Ethernet connections (it probably should be).


Installation of Bridge Management software:-

The program you’re going to need is called brctl and is included in bridge-utils. Find it in Synaptic, or install it using this command:

# aptitude install bridge-utils

This program will allow us to set up and use the bridge interface. The bridge interface appears as a new interface in ip link, much like eth0 or eth1. It doesn’t physically exist on your computer, but instead it is a virtual interface that just takes the packets from one physical interface, and transparently routes them to the other

Setting up your Bridge
Manual bridge setup

Note: All these commands are to be issued on the computer with the existing network connection. To set up the computer that’s going to be bridged, just set it up normally, as you would any other computer. You CAN use DHCP, or you can use a static address. It doesn’t matter.


Note: If, after trying to use the bridge interface, you find your network link becomes dead and refuses to work again, it might be that the router/switch upstream is blocking "unauthorized switches" in the network (for example, by detecting BPDU packets). You'll have to change its configuration to explicitly allow the host machine/network port as a "switch".
First step to creating the bridge network is actually creating it. Issue this command to get the ball rolling and create the new interface.

# brctl addbr br0

The name br0 is totally up to you, this is just an example name that I’ve chosen for the wiki article. Anyway, now that you have your bridge device, you have to add the interfaces that are gonna be bridged. You can cross-check the enumeration of your ethernet devices with (eth0, eth1, etc. is common):

# ip addr show

Add both the interface with the second computer, and the interface that leads to the existing network. Do it with this command:

# brctl addif br0 eth0 eth1

This will add the two interfaces eth0 and eth1 to bridge br0. Simple enough. There’s no distinction with how you add the bridges, or what order you do it, or any special commands you have to add to distinguish them. So don’t worry about that.
Well, now we have our bridges, so bring all the interfaces up, and you’ll be set!

Configuring bridging in /etc/network/interfaces


To make your bridge a little more permanent, you’re gonna need to edit /etc/network/interfaces. Using our example names, make it look like this and you’re set (if you want to use DHCP): 

# This file describes the network interfaces available on your 
# system and how to activate them. For more information, see interfaces (5).

 # The loopback network interface
 auto lo br0
 iface lo inet loopback

 # Set up interfaces manually, avoiding conflicts with, e.g., network manager
 iface eth0 inet manual
 iface eth1 inet manual
 # Bridge setup
 iface br0 inet dhcp
        bridge_ports eth0 eth1



To bring up your bridge, you just have to issue #ifup br0 and it’ll bring up the other necessary interfaces without anything in your interfaces file about the bridged interfaces.

If you like static IP’s, then you can just add the static IP options under the br0 interface setup. Kind like this: 

 # This file describes the network interfaces available on your system
 # and how to activate them. For more information, see interfaces(5). 
 # The loopback network interface
 auto lo br0
 iface lo inet loopback

 # Set up interfaces manually, avoiding conflicts with, e.g., network manager
 iface eth0 inet manual

 iface eth1 inet manual

 # Bridge setup
 iface br0 inet static
        bridge_ports eth0 eth1
        address 192.168.1.2
        broadcast 192.168.1.255
        netmask 255.255.255.0
        gateway 192.168.1.1

Useful options for virtualised environments:


Some other useful options to use in any stanza in a virtualized environment are: 

bridge_stp off       # disable Spanning Tree Protocol
        bridge_waitport 0    # no delay before a port becomes available
        bridge_fd 0          # no forwarding delay


Setting up bridge-related kernel variables
There are several kernel variables that affect bridge operation. In some cases you may need to tweak these variables. There are two common options:
·         Add variables to /etc/sysctl.conf directly
·         Put them to a sysctl configuration file fragment (e.g. /etc/sysctl.d/bridge_local.conf)
In the latter case, the procps init script should take care of loading them during boot. However, on Squeeze it does not, and you need to restart it from /etc/rc.local (or similar):
# /etc/rc.local
# Load kernel variables from /etc/sysctl.d
/etc/init.d/procps restart
exit 0
Libvirt and bridging
Libvirt is a virtualization API which supports KVM and various other virtualization techniques. In many cases, it's desirable to share a physical network interface with quests i.e. setup a bridge they can use. This operation is composed of two parts:
·         Setup the bridge interface on host as described in this article.
·         Configure guest to use the newly-created bridge
You can verify if bridging is working properly by looking at brctl output:
 root@server:/etc/libvirt/qemu# brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.001ec952d26b       yes             eth0
                                                        vnet0
                                                        vnet1
                                                        vnet2
virbr0          8000.000000000000       yes
As can be seen, guest network interfaces vnet0, vnet1 and vnet2 are bound with the physical interface eth0 in the bridge br0. The virbr0 interface only used for NAT connectivity with libvirt.

Attaching virtual devices to the appropriate bridge

We have created two Bridge br0 and br1 as per above given commands in which we added eth0 interface into bridge br0 and interface eth1 into br1 bridge.

Now we created a virtual XEN machine configuration to create a new XEN Dom U machine.

root@node01# cat cloudwas.cfg
kernel = "/usr/lib/xen-4.1/boot/hvmloader"
builder='hvm'
memory = 8000
shadow_memory = 8
name = "cloudwas"
vif = ['mac=00:11:4e:00:00:53, bridge=br1', 'mac=00:11:4e:00:00:54,  bridge=br0']
disk = [ 'file:/Images/cloudwas.img,ioemu:hda,w','file:/Images/OS_ISO/rhel-server-5.8-x86_64-dvd.iso,hdc:cdrom,r' ]
device_model = '/usr/lib/xen-4.1/bin/qemu-dm'
boot='cda'
serial='pty'
vnc=1

We can define MAC Address as per our requirement and can bind with bridge br0 and br1. In this virtual Dom U machine will have 2 interface connected with bridge br0 (connected to eth0) and br1 (connected to eth1).
==================================================





No comments:

Post a Comment