LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Virtualization and Cloud (https://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/)
-   -   KVM network problem. (https://www.linuxquestions.org/questions/linux-virtualization-and-cloud-90/kvm-network-problem-905743/)

ThomasRonshof 09-30-2011 02:23 AM

KVM network problem.
 
Hi,

I'm having problems with the network in Cent OS 6.0.

My Cent OS 6.0 host has IP 192.168.10.40. The gateway 192.168.10.1.
I want to create a Cent OS 6.0 guest with IP 192.168.10.41, so that all the clients on network 192.168.10.x can access this virtual server with ssh/telnet. Is this not possible ?

I can't get it to work. In Cent OS 5.7 it just worked out of the box. Because xen was with bridge network as default. Now in kvm its NAT. Så I just get a DHCP adress of something like 192.168.122.x.
So I have found out, that I must define a bridge network i kvm. But how ?

I've read the RH Virtualization doc and don't find the solution there and googlet alot.

Help will be apreciated.

Regards Thomas

Greenfuse 09-30-2011 02:56 AM

create /etc/sysconfig/network-scripts/ifcfg-br0 by copying it from /etc/sysconfig/network-scripts/ifcfg-eth0 then edit both files to match what you need, something like I have listed below


/etc/sysconfig/network-scripts/ifcfg-br0
Code:

DEVICE="br0"
ONBOOT=yes
TYPE=Bridge
BOOTPROTO=static
IPADDR=192.168.10.40
GATEWAY=192.168.10.1
DELAY=0


/etc/sysconfig/network-scripts/ifcfg-eth0
Code:

DEVICE="eth0"
ONBOOT=yes
TYPE=Ethernet
HWADDR=00:12:13:14:AB:CD
BRIDGE=br0

Then do 'service network restart'

ThomasRonshof 09-30-2011 04:15 AM

Thans :-) So simple, when seeing it.

Many thanks. It works now !

Regards

spankbot 10-05-2011 11:39 PM

Quote:

Originally Posted by Greenfuse (Post 4486237)
create /etc/sysconfig/network-scripts/ifcfg-br0 by copying it from /etc/sysconfig/network-scripts/ifcfg-eth0 then edit both files to match what you need, something like I have listed below


/etc/sysconfig/network-scripts/ifcfg-br0
Code:

DEVICE="br0"
ONBOOT=yes
TYPE=Bridge
BOOTPROTO=static
IPADDR=192.168.10.40
GATEWAY=192.168.10.1
DELAY=0


/etc/sysconfig/network-scripts/ifcfg-eth0
Code:

DEVICE="eth0"
ONBOOT=yes
TYPE=Ethernet
HWADDR=00:12:13:14:AB:CD
BRIDGE=br0

Then do 'service network restart'

I'm new to KVM networking and have a few questions. The commands above just creates a bridge, correct? You would still need to create a virtual interface and add it to the bridge?

Greenfuse 10-06-2011 06:02 AM

When you create the file for br0 as above and restart the network on the host machine then /dev/br0 becomes available as a bridged network interface It will effectively replace eth0 on the host machine as the network interface.

When you create a guest virtual machine you can select br0 as the interface for the guest system to connect through. (I have only done this with virt-manager - it will be available to select within the properties of the guest networking device). The network interface in the guest machine can be given an IP address which is in the same subnet as the host machine and it will function in the network as if it was a physical machine within the network.

I hope this helps make it more clear

spankbot 10-06-2011 04:17 PM

Thats very helpful, Greenfuse. Thanks.

So does anyone know what the qemu -net option would look like in order to get your vm to use this interface? I'm obviously not using virt-manager...

spankbot 10-06-2011 05:00 PM

ok, I answered my own question. For those of use not using virt-manager, you still need to create a virtual interface (tap0) and add it to the bridge (br0) using the bridge-utils and tunctl packages. I use a script to do this right before the VM starts.


Code:

#!/bin/sh
# qemu startup script
#
# This script first creates a virtual network interface (tap0) for the vm and adds it to the bridge (br0) before starting qemu.
#
/usr/sbin/tunctl -b
/sbin/ifconfig tap0 up
/usr/sbin/brctl addif br0 tap0
qemu-system-x86_64 -hda disk.img -boot d  -m 1024 -net nic -net tap,ifname=tap0,script=no -no-acpi

This is for an old Ubuntu 6 vm, by the way...

I wrote this all up in more detail here: http://www.kevitivity.com/2011/10/br...with-kvm-qemu/

DJOtaku 01-19-2012 08:35 PM

I have a question - do you need to create a brX for each VM if you want each one to have its own IP address?

ThomasRonshof 01-20-2012 01:34 AM

Hi,
No you don't need to.

DJOtaku 01-20-2012 07:34 AM

Just need to make sure I understand. in the ifcfg-br0 you set an IP address. If I were to have 5 VMs all running at the same time connected to br0, they could all have different IPs addresses that everyone in the network could address?

dyasny 01-20-2012 04:24 PM

think of br0 as the switch, the other vms are plugged into. it's own ip belongs to the host, not the vms

DJOtaku 01-20-2012 07:48 PM

OH, that makes a lot more sense. Now if only the br0 could work nicely with network manager, I'd be in business!

dyasny 01-22-2012 01:08 PM

No, NM is a bad bad bad idea when working with bridges. Just set everything up manually, and let it work.

DJOtaku 01-22-2012 07:07 PM

yeah, I get that. But it'd be nice if it would work correclty


All times are GMT -5. The time now is 07:19 PM.