How to generate DHCP Decline scenario / packets

dhcpdhcp-serverisc-dhcpnetworking

I have a dhcp packets sniffer, which needs to log if it sees dhcp decline response coming from client.I need to know the scenario where client can send dhcp decline response to dhcp server.
I tried to get this reproduce by minimizing small range of ip's at dhcpserver and allocating duplicate static ip's to a client says client_A and running dhclient on client_B.But client_B accepts duplicate ip (ip which is already with ip client_A), instead of sending dhcpdecline response.

Is this a better and guaranteed way to reproduce dhcp decline scenario.
Clients I m using are ubuntu and for dhcp server various options are available like vyos/microsoft.

Thanks and advance !!

Best Answer

It looks like it should be possible, but it's going to require a bit of fiddling...

As you suggested in the comments, dhclient doesn't validate DHCP server responses for router addresses so I went to the documents and found out what kind of situation might cause dhclient to send a DHCPDECLINE.

Dhclient docs show that dhclient-script is called when a lease is issued:

...network configuration script invoked by dhclient when it gets a lease. If unspecified, the default CLIENTBINDIR/dhclient-script is used. See dhclient-script(8)for a description of this file.

http://manpages.ubuntu.com/manpages/wily/en/man8/dhclient.8.html

Dhclient-script docs show that before configuring the address offered by the DHCP server, dhclient-script ARPs for it and raises a DHCPDECLINE if the address already exists.

Before actually configuring the address, dhclient-script should somehow ARP for it and exit with a nonzero status if it receives a reply. In this case, the client will send a DHCPDECLINE message to the server and acquire a different address.

http://manpages.ubuntu.com/manpages/wily/en/man8/dhclient-script.8.html

I haven't got a copy of Ubuntu to look at at the mo (check your /etc/dhclient-script), but the source code for the Linux dhclient-script can be found here http://bazaar.launchpad.net/~ubuntu-branches/ubuntu/wily/isc-dhcp/wily/view/head:/client/scripts/linux

I'm thinking (but unfortunately can't test it) that you could backup your existing dhclient-script and edit this section

 Must be used on exit.   Invokes the local dhcp client exit hooks, if any.
exit_with_hooks() {
  exit_status=$1
  if [ -f /etc/dhclient-exit-hooks ]; then
    . /etc/dhclient-exit-hooks
  fi
# probably should do something with exit status of the local script
  exit $exit_status
}

I think changing exit $exit_status to exit 1 would cause any DHCP lease to be declined...

Give it a try. If it works as I think it should, it will totally break the DHCP client but should generate a DHCPDECLINE each time you run dhclient.

Related Topic