LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat
User Name
Password
Red Hat This forum is for the discussion of Red Hat Linux.

Notices


Reply
  Search this Thread
Old 12-24-2012, 12:56 AM   #1
pandasatishkumar
LQ Newbie
 
Registered: Dec 2012
Location: Kolkata
Posts: 1

Rep: Reputation: Disabled
How to configure Bridge Networking In Redhat Linux 6


Dear Sir,
I have installed Redhat Enterprise Linux 6. Then i have installed Windows xp in KVM. But windows xp does not take my lan ip. Please help me. how to configure bridge network in Linux KVM.


satish kumar panda
 
Old 12-24-2012, 02:09 AM   #2
rylan76
Senior Member
 
Registered: Apr 2004
Location: Potchefstroom, South Africa
Distribution: Fedora 17 - 3.3.4-5.fc17.x86_64
Posts: 1,552

Rep: Reputation: 103Reputation: 103
You will need to setup bridged networking via a script.

For example, I'm running Centos 6 inside a physical Centos 6 machine. My physical Centos 6 machine is at 172.17.12.6 and my virtual Centos 6 machine is at 172.17.12.2 - my virtual Centos 6 machine provides DHCP/DNS and primary domain control at one of my employer's sites from inside the Centos 6 physical machine, using bridged networking to get onto the local intranet to render services, from "inside" the KVM instance running on the physical machine.

My intranet gateway to the internet is at 172.17.12.9

E. g. to run bridged networking you will need to have TWO IP addresses - one for your physical host and one for your virtual guest.

You will need these packages to be installed (you may need to download and compile / install them before this will work) - where you will get them with your distro I don't know, I use Centos 6 so my guide is based on that::

Quote:
rpm -ivh glib2-devel-2.22.5-5.el6.x86_64.rpm from centos dvd
rpm -ivh keyutils-libs-devel-1.4-1.el6.x86_64.rpm from centos dvd
rpm -ivh libcom_err-devel-1.41.12-3.el6.x86_64.rpm from centos dvd
rpm -ivh libsepol-devel-2.0.41-3.el6.x86_64.rpm from centos dvd
rpm -ivh libselinux-devel-2.0.94-2.el6.x86_64.rpm from centos dvd
rpm -ivh krb5-devel-1.8.2-3.el6.x86_64.rpm from centos dvd
rpm -ivh openssl-devel-1.0.0-4.el6.x86_64.rpm from centos dvd
rpm -ivh tunctl-1.5-3.el6.x86_64.rpm from centos dvd

Compile and install qemu-kvm-release.tar.gz from elsewhere.
Compile and install qemu-kvm-1.2.0-rc2.tar.gz from elsewhere - note that the version may differ, this is what I used October 2012 when it was current.
Compile and install openvpn-2.2.2.tar.gz from elsewhere - you may need to ./configure it with the --disable-lzo option to get it to compile.
Then, make sure your phyiscal machine (in my case 172.17.12.6) has in its /etc/rc.local - e. g. will start up each time it boots - these commands:

Code:
modprobe kvm_intel
modprobe kvm
modprobe tun
must go into the physical machine's rc.local.

Reboot to execute them or do them manually so that the needed modules are loaded.

I got this script off the net to setup bridged networking - all you need to do is put in, at the top, the IP address of your PHYSICAL host machine. It uses openvpn and tunneling to do the bridge - as you can see above you had to compile and install openvpn and modprobe tun for this:

Code:
#!/bin/sh 
# 
# script to bring up the tun device in QEMU in bridged mode 
# first parameter is name of tap device (e.g. tap0)
#
# some constants specific to the local host - change to suit your host
#
ETH0IP=172.17.12.6
GATEWAY=172.17.12.9
BROADCAST=172.16.255.255
#
# First take eth0 down, then bring it up with IP 0.0.0.0 
#
/sbin/ifdown eth0
/sbin/ifconfig eth0 0.0.0.0 promisc up
#
# Bring up the tap device (name specified as first argument, by QEMU)
#
/usr/local/sbin/openvpn --mktun --dev $1 --user `id -un`
/sbin/ifconfig $1 0.0.0.0 promisc up
#
# create the bridge between eth0 and the tap device
#
/usr/sbin/brctl addbr br0
/usr/sbin/brctl addif br0 eth0
/usr/sbin/brctl addif br0 $1
# 
# only a single bridge so loops are not possible, turn off spanning tree protocol
#
/usr/sbin/brctl stp br0 off 
# 
# Bring up the bridge with ETH0IP and add the default route 
#
/sbin/ifconfig br0 $ETH0IP netmask 255.255.0.0 broadcast $BROADCAST
/sbin/route add default gw $GATEWAY
Save the above file as qemu-ifup.sh or whatever. Also create a networking shutdown script like this:

Code:
#!/bin/sh 
# 
# Script to bring down and delete bridge br0 when QEMU exits 
# 
# Bring down eth0 and br0 
#
/sbin/ifdown eth0
/sbin/ifdown br0
/sbin/ifconfig br0 down 
# 
# Delete the bridge
#
/usr/sbin/brctl delbr br0 
# 
# bring up eth0 in "normal" mode 
#
/sbin/ifconfig eth0 -promisc
/sbin/ifup eth0 
#
# delete the tap device
#
/usr/local/sbin/openvpn --rmtun --dev $1
route del default
/sbin/ifconfig eth0 down
/sbin/ifconfig eth0 172.17.12.6 netmask 255.255.0.0 broadcast 172.17.255.255 up
route add default gw 172.17.12.9 eth0
and call this file qemu-ifdown.sh or whatever.

As you can see, the shutdown script shuts down the bridge and restores my physical machine's 172.17.12.6 IP.

Both of these are to be run on the physical machine - qemu_ifup.sh to start bridged networking, and qemu_ifdown.sh to shut down networking once the VM exits.

So, I wrote a run_vm.sh script that then does this:

Code:
sh -f qemu-ifup.sh tap0

/usr/local/kvm/bin/qemu-system-x86_64 vdisk.img -m 2048 -smp 2 -vnc 172.17.12.2:1 -net nic -net tap,ifname=tap0,script=no

sh -f qemu-ifdown.sh tap0
E. g. I run run_vm.sh as root on the physical host and it will then

Quote:
- Start up bridged networking on the physical machine
- Start the VM using the named bridge device as network access (tap0) to the outside world
- Once the VM exists, shut down bridged networking and restore to the physical machine's eth0 in an unbridged state
Then, INSIDE your vm, in its rc.local, put this to connect it to the local intranet. The VM will transparently use 172.17.12.6 (the physical machine's IP) to respond at 172.17.12.2 - e. g. you can, once the VM has started up and executed the below virtual rc.local on itself, access the VM at 172.17.2.2 "as if" it was "really" at that IP - meanwhile it is bridged in from 172.17.12.6 - so to the "world" it looks as if the VM is at 172.17.12.2 which is what you want.

VM's rc.local:

Code:
/sbin/ifconfig eth0 172.17.12.2 netmask 255.255.0.0 broadcast 172.16.255.255
route add default gw 172.17.12.9 eth0
e. g. this starts the VM's networking inside it and assigns it a 172.17.12.2, with access to the gateway at 172.17.12.9 for it.

Then, once the VM has started up, you can access it from the 172.17.12.6 physical host by simply SSH'ing into it:

Code:
ssh -luser 172.17.12.2
and from then on the VM behaves exactly as if it is a physical host on the network located at IP 172.17.2.2 - the ACTUAL physical host then being at 172.17.12.6 and just passing along traffic to the VM "as if" the VM is at 172.17.12.2

E. g. for your Windows instance, do exactly the same for the XP virtual machine, except for then simply using the Network Properties to set the XP VM's IP instead of the rc.local for the VM I give above.

Once you've done this in your XP virtual machine, you should see that your XP virtual machine is then capable of contacting the network / surfing the internet exactly "as if" it was a physical XP machine on your network, only now it is running inside a KVM VM on your Linux machine.

Hope this helps?

Last edited by rylan76; 12-24-2012 at 02:12 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to configure bridge networking virtualbox on slackware 13.37 ? wubai Linux - Virtualization and Cloud 1 09-02-2012 01:41 AM
Linux (2.6.32-220) networking bridge not receiving DHCP address automatically maccas17 Linux - Networking 1 05-21-2012 04:18 AM
Configure Linux box as bridge for XBox 8th sin Linux - Networking 6 02-03-2007 02:36 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Red Hat

All times are GMT -5. The time now is 04:59 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration