Problem serving DHCP to Virtual Guests

Phil Meyer pmeyer at themeyerfarm.com
Tue Nov 29 15:58:46 UTC 2011


On 11/28/2011 12:07 PM, Patrick Lists wrote:
> Hi,
>
> I have a workstation with Fedora 16 using NetworkManager getting a
> static IP address via DHCP from a central DHCP server. I have a couple
> of VMs on that workstation that use a routed network device in libvirt
> that I would also like to acquire their IP address from the central DHCP
> server.
>
> I set up the virtual routed network device virbr1 and configured a VM
> (with CentOS 6) to use it. When the VM starts I see in Wireshark the
> DHCP broadcasts on the virbr1 interface but those broadcasts are not
> seen on the p21p1 (the old eth0) interface on the workstation and
> definitely don't make it to the central DHCP server. I guess I may need
> some additional IPTables rules to forward the VMs DHCP requests to the
> central DHCP server? Does anyone know what IPTables rule(s) I should add
> to make this work?
>

My understanding and experience is that you really want to bridge the 
virtual machines to get them on the real network.

It can get very interesting when you add VLANs per virtual machine, or 
groups of virtual machines.

NetworkManager can handle bridges ok, and I do so on my desktop, but on 
all of our VM servers we shut of/don't install NetworkManager and just 
use network.

The principles are the same which ever you wish to use.

# yum -y install bridge-utils

This is a blip from our kickstart post-install for desktops and 'livecd' 
based VM servers:

# set up a bridge on eht0

cat > /etc/sysconfig/network-scripts/ifcfg-br0 <<_EOF
DEVICE=br0
ONBOOT=yes
TYPE=Bridge
BOOTPROTO=dhcp
STP=off
DELAY=0
NM_CONTROLLED="yes"
_EOF

cat > /etc/sysconfig/network-scripts/ifcfg-eth0 <<_EOF
DEVICE=eth0
ONBOOT=yes
BRIDGE=br0
NM_CONTROLLED="yes"
_EOF

This gives you the bridge, and all the virt tools will see it.  You 
would use p21p1, of course, or force udev to give you the old names.

Now that you have the bridge, you can specify it in the installs of your 
VMs.


They can do dhcp on the same network the server does.

This can be extended without much fuss to include VLANs as well.  Here 
is a sample from a startup script for a livecd based VM server that 
requires a different VLAN for one of the two VMs he serves:

modprobe 8021q
vconfig add eth1 840
vconfig add eth1 60
ifconfig inet 0.0.0.0 eth1.60

cat > /etc/sysconfig/network-scripts/ifcfg-br1 <<_EOF
DEVICE=br1
ONBOOT=yes
TYPE=Bridge
BOOTPROTO=none
STP=off
DELAY=0
_EOF

cat > /etc/sysconfig/network-scripts/ifcfg-eth1.60 <<_EOF
DEVICE=eth1.60
ONBOOT=yes
VLAN=yes
BRIDGE=br1
_EOF

cat > /etc/sysconfig/network-scripts/ifcfg-eth1.840 <<_EOF
DEVICE=eth1.840
ONBOOT=yes
VLAN=yes
IPADDR=10.150.0.102
NETMASK=255.255.252.0
_EOF

ifup eth1.840
ifup eth1.60
ifup br1

It is my experience that when using tagged VLANs such as this, that the 
bridge cannot successfully do dhcp because the underlying VLAN does not 
come up until after the bridge in this case.  Other than that one 
CAVEAT, this works well.

Need a VM on VLAN 60?  Just define his interface on bridge br1.  No need 
to do any bridging or VLAN setup inside the VM.

Bridges are the bomb.  Use 'em.

Good luck!



More information about the users mailing list