# KVM Bridged with NetworkManager

## marcelvs

Hello, is there a way to create a virtual machine that is visible in a network with KVM and the host uses NetworkManager ? 

Why that ? Because I want to create kvm guests in my notebook using the wlan0 interface. I noticed NetworkManager does not work with the TUN/TAP bridge ( because NM does not deal with the br0 interface ).

A nat solution was possible but I could not connect my guest from outside. 

I tried a VDE network but VDE promisses a lot and it  deliveres a little ( I read a lot of howtos and VDE makes everything I was already able to do easier but there is no plus, no way of tell to connect my host and guests in the outside network).

If some one have any idea I would be glad.

Thanks in advance,

Marcelo.

----------

## Mad Merlin

Most wireless cards don't work with bridging anyways. However, you can do a 1:1 static NAT (SNAT and DNAT the full range of ports for a private IP address to a regular IP alias on your LAN), something like this: http://forums.novell.com/suse/suse-product-discussion-forums/suse-linux-enterprise/suse-linux-enterprise-server-sles/sles-networking/412357-iptables-static-nat.html

Alternatively, you could try a routing approach to have guests communicate both ways, possibly something like this: http://tjworld.net/wiki/Linux/KvmQemuEasyRoutedNetwork

----------

## marcelvs

 *Mad Merlin wrote:*   

> Most wireless cards don't work with bridging anyways. However, you can do a 1:1 static NAT (SNAT and DNAT the full range of ports for a private IP address to a regular IP alias on your LAN), something like this: http://forums.novell.com/suse/suse-product-discussion-forums/suse-linux-enterprise/suse-linux-enterprise-server-sles/sles-networking/412357-iptables-static-nat.html
> 
> Alternatively, you could try a routing approach to have guests communicate both ways, possibly something like this: http://tjworld.net/wiki/Linux/KvmQemuEasyRoutedNetwork

 

This one works partially, I could communicate between the VM and the host, but the routing did not work (no communication with my gateway ) .  I think it might be something wrong with my configuration, kernel options, etc.

The nat stuff I did not try because I think the routing solution is the best solution. I think would be more clever to know why I cannot route packets. If there is some gentoo howto about routing ( not how to do a router ). I found some but it did not work. I am probably missing something.

The second step is to learn how to use wisely KVM ( with libvirt and virt-manager ) in order to be free of the ugly command line of KVM. I know RedHat works out-of-the-box with virt-manager, so I must be able to discover how with Gentoo.

Anyway, thanks for your help.

----------

## Hu

How did you determine that the guest was not communicating with the gateway?

----------

## marcelvs

 *Hu wrote:*   

> How did you determine that the guest was not communicating with the gateway?

 

Because the guest was able to ping the host, but could not ping the gateway ( my router ) nor my other computer in the network. One other strange thing that happened was I could ssh to the guest but I could not mount a windows xp samba share from the guest in my host ( I tested with debian and Windows XP VMs). So locally I could do everything between host and guest, except samba shares and outside the host nothing worked.

----------

## Mad Merlin

That doesn't indicate that your wireless card bridged successfully. Assuming you gave the bridge itself an IP, your host can talk to the guest directly through it when the guest's tap is bridged into the bridge.

----------

## radzior

networkmanager as of version 0.9.8 (not in the portage yet?) is now supposed to have support for bridging

----------

## alinefr

I did it with a tap interface in a laptop with wicd, but it didn't involve wicd at all (and it shouldn't involve network-manager, of course!)  

My /etc/conf.d/net

```

preup() {

        if [ ${IFACE} = tap0 ]; then

                /usr/bin/tunctl -u aline -t ${IFACE} > /dev/null 2>&1

        fi

        return 0

}

postdown() {

        if [ ${IFACE} = tap0 ]; then

                /usr/bin/tunctl -d ${IFACE} > /dev/null 2>&1

        fi

        return 0

}

config_tap0="10.0.0.1 netmask 255.255.255.0 broadcast 192.168.254.255"

```

My iptables rules:

```

#!/bin/bash

IPTABLES='/sbin/iptables'

WLANIF=wlp2s0

ETHIF=eno1

TAPIF=tap0

$IPTABLES -t nat -A POSTROUTING -o $WLANIF -j MASQUERADE

$IPTABLES -t nat -A POSTROUTING -o $ETHIF -j MASQUERADE

$IPTABLES -I FORWARD 1 -i $TAPIF -j ACCEPT

$IPTABLES -I FORWARD 1 -o $TAPIF -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT

```

WLANIF and ETHIF are my wifi and wired interfaces, respectively.

Then, in the guest (Windows 7, my one) I did configure a static IP:

IP address: 10.0.0.2

netmask: 255.255.255.0

Gateway: 10.0.0.1

And started qemu-kvm with:

-net tap,ifname=tap0,script=no

----------

## _______0

 *Mad Merlin wrote:*   

> Most wireless cards don't work with bridging anyways. However, you can do a 1:1 static NAT (SNAT and DNAT the full range of ports for a private IP address to a regular IP alias on your LAN), something like this: http://forums.novell.com/suse/suse-product-discussion-forums/suse-linux-enterprise/suse-linux-enterprise-server-sles/sles-networking/412357-iptables-static-nat.html
> 
> Alternatively, you could try a routing approach to have guests communicate both ways, possibly something like this: http://tjworld.net/wiki/Linux/KvmQemuEasyRoutedNetwork

 

First link broken.

And question about the second one. Same procedure for ipv6? When a system has two nics for them to talk to each other and forgoing bridging solutions routing is the only way?

How to do this with ipv6?

thanks

----------

