# KVM network bridge

## CyberMuz

Hi guys!

I'm trying to set up networking between my machine and a VM machine running on in. I would like to set up network bridge. I have followed some guides (for example http://en.gentoo-wiki.com/wiki/KVM) but now I'm stuck. 

On my host machine I have eth0 interface that I use to connect to local network and internet. The address for this interface is assigned by dhcp host on local network. I have added bridge br0 and tap0 interface. My setup (I have added the symlinks for br0 and tap0 to net.lo):

```

#/etc/conf.d/net

bridge_br0="eth0 tap0 "

brctl_br0="setfd 0 sethello 0 stp off"

rc_need_br0="net.tap0 "

config_br0="dhcp"

config_tap0="null"

tuntap_tap0="tap"

tunctl_tap0="-u goran"

mac_tap0="52:54:00:12:34:56"

config_eth0="null"
```

Now when I boot my host I end up with this situation:

The br0 has the correct IP address, that address was before assignet to eth0. But eth0 has wrong address and I cant access the network or the internet. 

```

# ifconfig -a

br0       Link encap:Ethernet  HWaddr 14:da:e9:bc:f1:38  

          inet addr:10.10.0.32  Bcast:10.10.0.255  Mask:255.255.255.0

          inet6 addr: fe80::16da:e9ff:febc:f138/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:123 errors:0 dropped:5 overruns:0 frame:0

          TX packets:14 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0 

          RX bytes:17144 (16.7 KiB)  TX bytes:1518 (1.4 KiB)

eth0      Link encap:Ethernet  HWaddr 14:da:e9:bc:f1:38  

          inet6 addr: fe80::16da:e9ff:febc:f138/64 Scope:Link

          UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1

          RX packets:152 errors:0 dropped:2 overruns:0 frame:0

          TX packets:22 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000 

          RX bytes:21808 (21.2 KiB)  TX bytes:2284 (2.2 KiB)

          Interrupt:18 Memory:fb800000-fb820000 

lo        Link encap:Local Loopback  

          inet addr:127.0.0.1  Mask:255.0.0.0

          inet6 addr: ::1/128 Scope:Host

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

          RX packets:157 errors:0 dropped:0 overruns:0 frame:0

          TX packets:157 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0 

          RX bytes:31077 (30.3 KiB)  TX bytes:31077 (30.3 KiB)

sit0      Link encap:IPv6-in-IPv4  

          NOARP  MTU:1480  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:0 

          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

tap0      Link encap:Ethernet  HWaddr 52:54:00:12:34:56  

          UP BROADCAST PROMISC MULTICAST  MTU:1500  Metric:1

          RX packets:0 errors:0 dropped:0 overruns:0 frame:0

          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:500                                                                                                                                                                                         

          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)       

```

When i start my Guest OS I have eth0 interface on it but it can't get address from dhcp. If I set IP manually (for example 10.10.0.100) I can't ping my host.

I start Guest OS with command:

```

qemu-kvm -hda gentoo-amd64.img -cdrom install-amd64-minimal-20120223.iso -boot d -net nic,model=virtio,macaddr=00:1d:92:ab:3f:77 -net tap,ifname=tap0,script=no,downscript=no

```

What am I missing?

Also if you could recommend me some good guides for network bridging on Gentoo I would be grateful. Most of the guides I have found seem out of date.

----------

## Mad Merlin

1) Don't set the MAC address of the tap manually, it'll only cause you headaches (one is autogenerated by the kernel).

2) I believe 

```
tunctl_tap0="-u goran"
```

 needs to be 

```
tuntap_tap0="-u goran"
```

3) What is your output from brctl show?

----------

## Jeffrey0

net.example says that you need a hard newline in between brctl_br0 settings like this:

```
brctl_br0="setfd 0

sethello 0

stp off" 
```

I assume that that'd throw very obvious errors at you instead of breaking everything silently, but it's worth a shot.

I had pretty much the same problem; in my case, it ended up being a routing issue. The way I diagnosed my problem was by comparing the output of `ifconfig -a`, `route -n` and `brctl show` both with and without the bridging set up in the configuration. I suggest rebooting in between to make sure that there's no leftovers from the other configuration (I know Debian doesn't handle removal of bridges right).

When you're using bridging, any IP addresses and routing should be set up on the bridge device (br0 in this case), not on eth0 directly. So it's normal for eth0 to not have an IPv4 address at all and eth0 itself shouldn't show up in the routing table either. Your ifconfig output looks fine to me.

Also, don't forget about any iptables rules that you might have set up. If you're using iptables, I suggest disabling it until you fixed your problem. Any rules that you do set up should be set on br0, not on eth0.

If it still doesn't work, you should probably try to set up basic connectivity manually first. Remove your networking stuff from the default runlevel, make an empty net file that sets config_eth0="null", reboot and do something like this (from memory, hope it's correct...):

```
brctl addbr br0

ifconfig eth0 up

brctl addif br0 eth0

ifconfig br0 up

ifconfig br0 10.10.0.32

route add default gw 10.10.0.1 dev br0 # you may have to change the gateway IP

ping 8.8.8.8 # should work
```

If that does work, try removing all of the tap0 settings and just getting a basic bridge set up first. A bridge with only one device in it is perfectly valid and works fine.

----------

## cach0rr0

if you fancy a few working examples

https://forums.gentoo.org/viewtopic-t-918390.html

https://forums.gentoo.org/viewtopic-t-895456.html

----------

## bbgermany

Hi,

don't forget to set ipforwarding.

bb

----------

## CyberMuz

Thank you guys for your help. It turns out that the problem was in Shorewall firewall configuration. When i shut it down everything was working. Now I just need to learn how to configure shorewall so that i can use it with this new setup.

----------

