You are not logged in.

#1 2012-04-07 00:23:50

Naijeru
Member
From: England
Registered: 2011-10-19
Posts: 23

[SOLVED] KVM and Bridged Networking

I've got KVM working and a Windows 2008 server installed on a image now, but it's only getting a NAT ip address. I need to get this server onto my main network, on Windows I'd use Virtual Box and Bridged Networking, but I thought I'd give KVM a try out.

I've followed the setup at https://wiki.archlinux.org/index.php/KV … Networking

Using Netcfg
Bridged networking is used when you want your VM to be on the same network as your host machine. This will allow it to get a static or DHCP IP address on your network, and then you can access it using that IP address from anywhere on your LAN. The preferred method for setting up bridged networking for KVM is to use the netcfg package. You will also need to install bridge-utils.
Netcfg#Configuring_a_bridge_for_use_with_virtual_machines_.28VMs.29

And this page https://wiki.archlinux.org/index.php/Ne … _.28VMs.29

I've got a bridge working I believe (all my stuff is DHCP by the way)

Output of ifconfig

br0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500  metric 1
        inet 192.168.1.52  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::21d:7dff:fea9:bb2f  prefixlen 64  scopeid 0x20<link>
        ether 00:1d:7d:a9:bb:2f  txqueuelen 0  (Ethernet)
        RX packets 2966  bytes 520670 (508.4 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2351  bytes 1874150 (1.7 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth0: flags=4419<UP,BROADCAST,RUNNING,PROMISC,MULTICAST>  mtu 1500  metric 1
        ether 00:1d:7d:a9:bb:2f  txqueuelen 1000  (Ethernet)
        RX packets 2977  bytes 570261 (556.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2364  bytes 1875202 (1.7 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
        device interrupt 45  base 0xc000

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 16436  metric 1
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 0  (Local Loopback)
        RX packets 72  bytes 7056 (6.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 72  bytes 7056 (6.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

I've got "bridge" added to my rc.conf as a MODULE which is loaded. (I saw reference to this somewhere else on the forum that this might be needed)

I'm starting my VM with the following command

qemu-kvm -vnc 192.168.1.52:0 -hda Nekomi -m 2048 -smp 2 -net nic

Yet I still can't get an IP outside of the 10.0.0.0 range on the VM.

The VNC line above is because the HOST has not VGA output at all, completely headless.

I'm trying to get this working and trying to learn at the same time. KVM is new to me, as is bridged networking on linux.

Any ideas? Thanks

Last edited by Naijeru (2012-09-18 16:28:20)

Offline

#2 2012-04-09 14:10:04

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 15,581

Re: [SOLVED] KVM and Bridged Networking

You will need to connect the bridged interface with the network card the VM uses, check the networking sections of the qemu wiki page
https://wiki.archlinux.org/index.php/QEMU#Networking

Last edited by Lone_Wolf (2012-04-09 14:10:18)


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#3 2012-04-26 11:36:27

Naijeru
Member
From: England
Registered: 2011-10-19
Posts: 23

Re: [SOLVED] KVM and Bridged Networking

Sorry for the delay, bit a PC rebuild occurred :-(

Anyway, I managed to get this working with steps #1-#7 from the linked section. Thanks for that. I did have a few minor issues in getting a DHCP on the host machine itself, turns out I'd missed a single ) from the daemons section of rc.conf. A human error, but difficult to fix as the machine was rendered off the network and without a VGA card... fun! smile

I diverge, I have this script to bring up a bridge when the qemu-kvm starts

 #!/bin/sh
 
 echo "Executing /etc/qemu-ifup"
 echo "Bringing up $1 for bridged mode..."
 sudo /sbin/ifconfig $1 0.0.0.0 promisc up
 echo "Adding $1 to br0..."
 sudo /usr/sbin/brctl addif br0 $1
 sleep 2

But when the kvm shutdowns it complains it can't find qemu-ifdown script. So I'm thinking of making one but just want to check it over first.

 #!/bin/sh
 
 echo "Executing /etc/qemu-ifdown"
 echo "Removing $1 from br0..."
 sudo /usr/sbin/brctl delif br0 $1
 echo "Taking down $1 from bridged mode..."
 sudo /sbin/ifconfig $1 0.0.0.0 promisc down
 sleep 2

I've reversed the logic here, is the above the correct way to bring down the guest interface?

Offline

#4 2012-04-26 11:56:54

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 15,581

Re: [SOLVED] KVM and Bridged Networking

It does look ok to me for bringing down.

some general comments :
ifconfig is part of net-tools and that package is deprecated.
Maybe change the script to use commands from the iproute2 package ?
(if you do, it's probably a good idea to add that to the Wiki)

The bridge br0 will be up permanently connected to the real network by following this method.
Is that desired behaviour for you ?

Last edited by Lone_Wolf (2012-04-26 11:58:20)


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

#5 2012-04-26 12:03:50

Naijeru
Member
From: England
Registered: 2011-10-19
Posts: 23

Re: [SOLVED] KVM and Bridged Networking

Thanks for the speedy reply, I'll investigate iproute2, I admit I'm extremely new to managing iptables and iproutes myself. (Ex Virtualbox/VMware user, it just does this stuff for you)

As far as I know, the way I've done it with that wiki, is that br0 is now my main interface on the host instead of eth0. I think this is okay, as this is just a spare PC on my home lan that will be used to host virtual machines for development.

I appreciate the feedback and will read up on iproute2. Thanks again

Offline

#6 2012-04-26 18:25:12

Naijeru
Member
From: England
Registered: 2011-10-19
Posts: 23

Re: [SOLVED] KVM and Bridged Networking

I've created the script now (as above for now). Yet when the VM shutdowns I'm left with this...

Executing /etc/qemu-ifup
Bringing up tap0 for bridged mode...
Adding tap0 to br0...
/etc/qemu-ifdown: could not launch network script

/etc/qemu-ifdown is owned by root:kvm, the same as /etc/qemu-ifup

4 -rwxr-x--x 1 root kvm   206 Apr 26 19:19 /etc/qemu-ifdown
4 -rwxr-x--x 1 root kvm   197 Apr 11 18:55 /etc/qemu-ifup

Any ideas why it can't run?

Offline

#7 2012-04-28 11:36:34

Lone_Wolf
Administrator
From: Netherlands, Europe
Registered: 2005-10-04
Posts: 15,581

Re: [SOLVED] KVM and Bridged Networking

it might have to do with sudo / permissions.

Check Qemu Wiki on networking .
You'll see they don't use sudo in the qemu-ifup & qemu-ifdown scripts, but instead use the sudoers file to allow users to run the scripts as root.
I suggest you change the scripts that way.

Note : the sudoers example they give uses User_Alias , on archlinux using the kvm group seems more appropriate.
something like :

Cmnd_Alias QEMU = /etc/qemu-ifup, /etc/qemu-ifdown

kvm ALL=(ALL) NOPASSWD: QEMU

should work i think.


Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.

clean chroot building not flexible enough ?
Try clean chroot manager by graysky

Offline

Board footer

Powered by FluxBB