# Kvm-guest and dhcp?

## Letharion

I have set up a few kvm guests with networking according to the instructions on the gentoo wiki.

This has worked well for me with static IPs, but I can never seem to allow a guest to talk to the dhcp-server.

Using the wiki as base, what do I need to do different/more?

----------

## Mad Merlin

Could you paste your complete KVM command line and the output of ifconfig and brctl show?

----------

## Letharion

Of course  :Smile: 

qemu-system-x86_64 -net nic,macaddr=52:54:00:12:34:56 -net tap,ifname=qtap0,script=no,downscript=no -m 1024 test.img

```
# ifconfig

br0       Link encap:Ethernet  HWaddr 66:12:0a:55:3c:98  

          inet addr:192.168.100.254  Bcast:192.168.100.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:0 

          RX bytes:33134 (32.3 KiB)  TX bytes:293622 (286.7 KiB)

eth0      Link encap:Ethernet  HWaddr 00:1d:09:16:14:20  

          inet addr:192.168.16.145  Bcast:192.168.16.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:100 

          RX bytes:281181937 (268.1 MiB)  TX bytes:16738813 (15.9 MiB)

          Memory:fdfe0000-fe000000 

lo        Link encap:Local Loopback  

          inet addr:127.0.0.1  Mask:255.0.0.0

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

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

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

          collisions:0 txqueuelen:0 

          RX bytes:4584 (4.4 KiB)  TX bytes:4584 (4.4 KiB)

qtap0     Link encap:Ethernet  HWaddr 66:12:0a:55:3c:98  

          UP BROADCAST RUNNING PROMISC MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:500 

          RX bytes:38034 (37.1 KiB)  TX bytes:293622 (286.7 KiB)

# brctl show

bridge name     bridge id               STP enabled     interfaces

br0             8000.66120a553c98       no              qtap0
```

----------

## Hu

According to that output, qtap0 is a bridge to nowhere, so the kernel will not be forwarding any KVM traffic out to the DHCP server on the physical network.  If you mean to bridge the guest to the outside world, you need to add a physical NIC to the bridge in addition to the tap device you already added.

----------

## Letharion

Ok, so I googled a bit, and tried

```
brctl addif br0 eth0
```

which seems to have "worked", but also forwards all traffic, meaning my host computer can no longer access the internet, so I don't know how to proceed.

----------

## Mad Merlin

 *Letharion wrote:*   

> Ok, so I googled a bit, and tried
> 
> ```
> brctl addif br0 eth0
> ```
> ...

 

Normally you remove the IP address from eth0 and set it to promisc (with 0.0.0.0, or config_eth0=( "null" ) in /etc/conf.d/net), after which point you treat br0 as you would have eth0 before (and probably give br0 an IP via DHCP). Now you can plug (additional) tap devices into br0 and it'll be as if they're connected to the same switch that eth0 is physically plugged into.

If you want to create a private network, add another bridge and don't plug any physical ethernet devices into it, you don't need to give the bridge an IP unless you want the guests to be able to reach the host.

----------

## expressionlibre

Hi,

I had the same problem because I also tried to follow the english KVM wiki.

Is this wiki up to date ? Can a specialist  check it ?

For me, network works only if br0 as got a LAN IP and eth0/tap0 have null config (0.0.0.0).

Personnally Bridge doesn't come up at booting process cause "tap0" does not exist at the moment.

After the boot, I restart net.br0 and everything is OK then...

My /etc/conf.d/net :

```

# setup a bridge for KVM

bridge_br0="eth0 tap0"

# give all interfaces null address

config_eth0=( "null" )

config_tap0=( "null" )

# give bridge an address

config_br0=( "dhcp" )

# dependance for the bridge

rc_need_br0="net.eth0 net.tap0"

# set some options to the bridge

brctl_br0=( "setfd 0" "sethello 0" "stp off" )

# define tap interfaces

tuntap_tap0="tap"

tunctl_tap0="-u me"

mac_tap0="00:1d:92:ab:ab:ab"

```

----------

## Mad Merlin

 *expressionlibre wrote:*   

> Hi,
> 
> I had the same problem because I also tried to follow the english KVM wiki.
> 
> Is this wiki up to date ? Can a specialist  check it ?
> ...

 

I have basically the same setup, and it works for me. The salient differences are that I have RC_NEED_br0= instead of rc_need_br0=, and I have this:

```

brctl_br0="setfd 0

sethello 0"

```

I'm not sure which is making the difference, but variable names in bash certainly are case sensitive, and if you weren't setting the forward delay to 0, it's fairly likely that your dhcp request would time out before the forward delay passed (the default is 30s, IIRC).

Also, there's no need to set the MAC address on the tap device, the kernel will pick a unique one automagically.

Finally, I assume you created /etc/init.d/net.tap0 as a symlink to /etc/init.d/net.lo?

----------

