Configure Networking with DHCP
This tutorial shows how to contextualize networking parameters in a virtual machine using standard networking tools. This approach can be followed if all your virtual machines can be placed in the same broadcasting domain.
System
Virtual Machine
As stated in the Requirements section, to handle networking contextualization you will need a dhcp server (we are using dhcp3-server package from debian in this howto). You also need to add dynamic machines to your dns server or, alternatively, add them to the /etc/hosts file in both your dhcp server machine and all the virtual machines using this contextualization.
An example of this configuration follows:
Excerpt from /etc/hosts with dynamic machines:
# Virtual Machine names 192.168.3.201 vm01 192.168.3.202 vm02 192.168.3.203 vm03 192.168.3.204 vm04
Excerpt from dhcp3-server configuration file describing machines.
host vm01 { hardware ethernet 00:16:3e:01:01:01; fixed-address vm01; option host-name vm01; } host vm02 { hardware ethernet 00:16:3e:01:01:02; fixed-address vm02; option host-name vm02; } host vm03 { hardware ethernet 00:16:3e:01:01:03; fixed-address vm03; option host-name vm03; } host vm04 { hardware ethernet 00:16:3e:01:01:04; fixed-address vm04; option host-name vm04; }
Here we are using MAC addresses to distinguish each node. This MAC addresses will be used to assign different names and IP addresses to dynamically deployed machines.
In order to let VMs configure correctly their network parameters, follow these steps:
request subnet-mask, broadcast-address, time-offset, routers, domain-name, domain-name-servers, host-name, netbios-name-servers, netbios-scope, interface-mtu;
hostname $new_host_name
To set the MAC address of a particular Virtual Machine you will need a line similar to the following one in the ONE VM description file:
NIC=[mac="00:16:3e:01:01:01"]
Summarizing, with the above setup, Virtual Machine with mac address 00:16:3e:01:01:01v would receive IP address 192.168.3.201 and hostname vm01 whenever it starts.