I'm trying to configure OpenNebula to use the DHCP server that already exists on my network. Yes, I already know that OpenNebula manages virtual mac addresses rather than IP addresses, but that doesn't tell me how to get this working. ;)
My guests and hosts are both CentOS, so I would imagine all that needs to be done is configure contextualization so that BOOTPROTO=dhcp is dumped into /etc/sysconfig/network-scripts/ifcfg-eth0.
- How do I configure contextualization so that this happens? Do I just modify my template in a certain way? If so, how is that done?
- Once I configure my template with these new contextualization settings, how should I configure my virtual network in ONE?
It seems like this should be easy to do, as this should appear to be simpler than managing a bunch of static IPs for vms, and you would think that this is a common use case. However, googleing so far has turned up very little.
Thanks!!
Edit: My DHCP server successfully gives my vm an ip address if I set BOOTPROTO=dhcp and DHCP_HOSTNAME=foo manually and restart networking on my vm. Which is fine, I would like to be able to set the hostnames of the vms I spin up too.
Now it's just a matter of determining how to make ONE do these things automatically/via the web interface or CLI tools. Also ONE still lists the IP address of the original lease, rather than the IP that DHCP gave my VM. It would be nice to get that issue fixed too.
My Opennebula is version 4.8.0. I had similar needs, so here is what I did:
The guest OS has to be manually set up to use DHCP. I don't know how to do that automatically, but that's not a big issue.
Here is how I proceeded further to have a template that uses DHCP. I went on to install a new operating system, for example CentOS 6.5.
Now every new VM that spawns from that template will be using the "DHCP" Virtual Network, will have a dynamic IP address and Opennebula will not display any IP address for such VMs.
I can't answer about the automatic setting of hostname, but I think it must be a matter of configuring the guest OS and the DHCP. On the other hand, DHCP must know what hostname to give to which MAC address and, since Opennebula will be generating those MAC addresses dynamically, I don't know how you can tell the DHCP server about them in advance.
Consider using a dhcpd config bit to set the interim hostnames on new boxes until you can hostnamectl them yourself. It has the advantage of setting a guessable hostname that you can use to connect, without having to grovel logs or guess the IP.
I grabbed this from a great post by Peter Rathlev, here: https://lists.isc.org/pipermail/dhcp-users/2013-March/016518.html . While it's in answer to another question, it does provide a GREAT example of how dhcpd can be configured to do amazing things, and at least do what I think you're needing.
For
v4.x
(less than 4.10?):First create a
VNET
, using whatever setup you want. For example, for a bridged network you might have:Next, create a lease, associated with that
VNET
. Note, the IP address is mandatory and unique, but is only used as the NIC 'key', if you're using DHCP (See below). Make sure to set the MAC address such that your DHCP server will offer it an address:Now add a NIC to your VM:
NETWORK="net0" IP="192.168.0.1" MODEL="virtio"
Now be sure to configure DHCP appropriately for that MAC address.
For
4.x > 10?
and5.x
, it's almost the same, except that leases are now replaced with address ranges:Create a VNET (almost) as above:
Then create an address range, only containing one address:
Use this AR in your VM:
And again set up DHCP as appropriate.
More information on address ranges here: