I have a situation where I am able to launch CentOS 6.6 images on a subnet such that the VM instances get their IP addresses from the virtual gateway of the subnet. Now this gateway has gone wonky and I don't have the access to fix it, so I have set up my own DHCP server on this subnet.
So now there are 2 DHCP servers on this subnet and my VMs are getting random IP addresses, sometimes from one DHCP server and sometimes from the other. My question is that how I can configure the dhcp client on my VMs so that they make DHCP requests to only my DHCP server rather than the faulty one? man dhcp.conf
has not been very helpful.
On CentOS 7 this can be achieved by creating the file
/etc/dhcp/dhclient.conf
and adding a line liketo reject DHCP offers from one server or the other (or in this example, from all DHCP servers on a specific subnet).
To filter DHCP offers only on a specific interface, place the
reject
directive inside aninterface
block:Note the interface name (here,
eth0
) must be placed in quotation marks, unlike the example shown in the man page fordhclient.conf
.In all cases, run
systemctl restart network.service
as the superuser for changes to take effect.On CentOS 6.7 the same instructions work, however
reject
rule would be added would be/etc/dhcp/dhclient-eth0.conf
(and there would clearly be no need to use aninterface
block).service network restart
, which again must be invoked as the superuser.DHCP works via a multicast request for an IP address. Which gets an IP address from the first DHCP server to respond. There is no way that I know of to force the client to get a DHCP address from a specific server.
In fact, running two DHCP servers that are not aware of each other is asking for the type of trouble you are running into. You need to get the faulty one shut down or fixed.