# QEMU - Setting Up Network Bridge

## sdauth

Hello,

So I stumbled upon this nice tutorial while researching on network bridge setup for qemu.

For those who don't want to watch the video, here is what he did (with steps adjusted for Gentoo) :

bridge setup (br0)

/etc/conf.d/net

```
bridge_br0="eth0"

config_br0="dhcp"

bridge_forward_delay_br0=0

bridge_hello_time_br0=1000
```

```
ln -s /etc/init.d/net.lo /etc/init.d/net.br0
```

Allow br0 :

/etc/qemu/bridge.conf

```
allow br0
```

Start the bridge :

```
rc-service net.br0 start
```

Start qemu with bridge helper and custom MAC address (each VM needs its own MAC address) so that the DHCP server on my router allocates a different IP to the VM :

```
qemu-system-x86_64 -name gentoo -enable-kvm -cpu host -smp cores=4,threads=1 -M q35 -m 8G -boot order=d -drive file=gentoo.img,format=raw,aio=native,cache=none -machine type=pc,accel=kvm \

-net nic,macaddr="52:54:12:11:3c:c0" -net bridge,br=br0
```

This is quite easy and works great, I can reach any VM just like it was a regular physical machine on my LAN. Now the question.. -as I'm not an expert in networking (understand noob here   :Laughing:  )-, is this the right way to do it ? This seems just too easy. Not that it is a wrong thing of course.   :Surprised: 

If you have other ways of doing it, please share !   :Smile: 

----------

## alamahant

You are 100% right.

This is how I also do it in openrc.

i also add

```

config_eth0="null"

```

In systemd i use nmcli.

The only difference I use virt-manager........

 :Smile: 

----------

## sdauth

Great.   :Smile: 

Now I tried to add "net.br0" to default runlevel so that the bridge is always present, here is the rc.log :

```
* Starting DHCP Client Daemon ...

 [ ok ]

 * Bringing up interface br0

 *   Caching network module dependencies

need dbus

 *   Creating bridge br0 ...

 *   Setting forward_delay: 0

 *   Setting hello_time: 1000

 *   Adding ports to br0

 *     eth0 ...

 [ ok ]

 *   dhcp ...

 *     Running dhcpcd ...

sending commands to master dhcpcd process

 [ ok ]

 *     received address 

 [ ok ]

 *   Waiting for tentative IPv6 addresses to complete DAD (5 seconds) .

 [ ok ]
```

So as you can see, I use dhcpcd (so I don't have any net.eth0 in /etc/init.d/; only dhcpcd is present at default runlevel as usual), does it look ok ? 

ip addr show

```
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP group default qlen 1000

4: br0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
```

Is the output similar for you ? Sorry if it sounds dumb (after all it works..   :Laughing:   ) but I just want to make sure I'm doing it right.

----------

## alamahant

Please add net.br0 not to default but rather to "boot" runlevel

```

rc-update add net.br0 boot

```

This is needed if during boot some services depend on network for their initialization.

Things like nfs ldap samba dns etc

 :Smile: 

----------

## sdauth

Ok thanks, good to know.   :Smile: 

----------

