4

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.

  1. 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?
  2. 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.

cat pants
  • 2,139
  • 10
  • 33
  • 44

3 Answers3

2

My Opennebula is version 4.8.0. I had similar needs, so here is what I did:

  1. I configured the DHCP server that already exists in our network to reserve an IP range for DHCP. The range was: 10.23.1.201 - 10.23.1.254. That's 54 dynamic IPs.
  2. I created a new Virtual Network, which I named "DHCP". On the tab "Addresses" I chose radio button "Ethernet". This way Opennebula will only give MAC addresses to the VMs using this network. I left "MAC Start" empty because it's optional anyway. I entered 54 in the "Size" field because my DHCP can provide this many dynamic IP addresses. So, Opennebula gives new VMs only a mac address and nothing more.

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.

  1. I created a template using this new Virtual Network and two disks - an ISO image and an empty datablock image set to "persistent = yes".
  2. Then, I instantiate the template, the VM boots up from the ISO and when I install the VM, I leave the network configuration to "dynamic".
  3. When the installation finishes, my VM has an automatically assigned IP from the DHCP server just like if it was a real machine.
  4. I then stop and delete the VM.
  5. Set the datablock image back to "persistent = no".

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.

Pavel Tankov
  • 367
  • 3
  • 15
  • How do you discover the address of VMs? Specifically, is there a way to get OpenNebula still to show the IP address that got assigned while using virtual network with ETHER type and external DHCP server? – tsaarni Jan 21 '15 at 06:52
  • Unfortunately, I don't know how to get Opennebula to show them yet. – Pavel Tankov Jan 21 '15 at 08:53
  • I would expect that a client with DHCP_HOSTNAME set will offer up a hostname to the dhcp server. If you've got it registering itself into DNS properly, it should record the mapping. If you're looking to find the IP for a host, it's probably so you can connect to it .. and using the name should be a reliable way to do that instead. IPs are ephemeral, after all, and we shouldn't cling to them. – user2066657 Aug 22 '16 at 13:00
0

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.

if (not (option host-name ~~ "^[a-z0-9][a-z0-9\-]+[a-z0-9]$")) {
    set new_host-name = concat("host-", binary-to-ascii(16, 8, "", substring(hardware, 1, 6)));
    log(concat("invalid hostname: ", option host-name, " => ", new_host-name));
    ddns-hostname = new_host-name;
} else {
    ddns-hostname = pick (option fqdn.hostname, option host-name, substring (option dhcp-client-identifier, 1, 20));
}

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.

user2066657
  • 336
  • 2
  • 13
0

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:

NAME = "net0"
TYPE = "FIXED"
BRIDGE = "br0"

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:

VNET = "net0"
IP = "192.168.0.1"
MAC = "02:00:d7:00:00:01"

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? and 5.x, it's almost the same, except that leases are now replaced with address ranges:

Create a VNET (almost) as above:

NAME = "net0"
VN_MAD = "dummy"
BRIDGE = "br0"

Then create an address range, only containing one address:

VNET= "net0"
SIZE = "1"
MAC = "02:00:d7:00:00:01"

Use this AR in your VM:

NETWORK="net0"
MAC="02:00:d7:00:00:01"
MODEL="virtio"

And again set up DHCP as appropriate.

More information on address ranges here:

match
  • 148
  • 7