27

What I'm trying to achieve is to get cold-start, zero-state DHCP lease which means forcing dhclient through the full discovery and configuration process (DHCPDISCOVER–DHCPOFFER–DHCPREQUEST–DHCPACK as opposed to the shortcutted DHCPREQUEST–DHCPACK cycle which uses a remembered address). I need this to debug a network configuration problem.

I have tried:

  • flushing current lease with dhclient -r, disconnecting the current Network Manager connection;
  • killing any leftover dhclient and dnsmasq processes;
  • cleaning /var/lib/dhcp/ directory, which supposedly contains the client lease database;
  • sudo restart network-manager.

But even after these steps I see in the logs DHCPDISCOVER immediately followed by DHCPREQUEST of somehow still remembered address.

Clearly, the OS is storing the address somehow else, and I've run out of ideas. Any help from the community?

  • Did you figure it out. I am also running into the same problem. There are lease files under NetworkManager as well. I deleted them as well. For some reason it still picks up the old address. – gudge Feb 26 '16 at 18:38
17

This did the trick for me(for eth0, run from sudo su):

dhclient -r -v eth0 && rm /var/lib/dhcp/dhclient.* ; dhclient -v eth0
  • 1
    When I did this I got a new lease, but the IP address does not seem to have been used by the system. If I try and ping the name or related IP address it fails. If I use ifconfig to check the current address, I can pind that. – TafT Aug 16 '16 at 17:05
  • Changing the rm part makes this work for me (without this the prior lease was used: dhclient -r -v eth0 && rm /var/lib/dhcp/dhclient* ; dhclient -v eth0) – davejagoda Apr 28 '17 at 17:08
6

DHCP Client program writes the lease to a file. Just delete the file and restart networkmanager.

/var/lib/dhcp/dhclient.leases

This is where the leases are stored, in my computer.

2

What you are seeing is not your machine remembering the IP. In syslog you see DISCOVER REQUEST OFFER ACK however this is not in the order that it happened. It actually went DISCOVER OFFER REQUEST ACK to confirm this you can sniff the traffic between the PC and upstream DHCP server. You sent DISCOVER the server sent back OFFER and you got the IP from the OFFER for your REQUEST

You did everything right however, when you did "dhclient -r" dhclient will send a unicast RELEASE and some ISPs only accept multicast packets to their DHCP server, so the RELEASE never got there, as far as the server is concerned your lease is still valid, so it gave you back the same IP in the OFFER.

  • Thanks for that! I've never understood why the log always shows DISCOVER, REQUEST, OFFER, ACK; as the sequence never made sense. Just knowing that that's not really what happens puts me a long way ahead in figuring my own problem. So, my machine is getting the DHCPOFFER of the IP I don't want, and then saying "OK", but if I force it to try to get anything else, then the server says DHCPNACK, and I end up with no network at all. At a guess, the reservation on the server is for the wrong MAC. – Auspex Oct 15 '18 at 15:43
  • Only thing I can think, you can try is change "hwaddress ether xx:xx:xx:xx:xx:xx" in /etc/network/interfaces if your ISP allows you to change your mac without having to ring them up and tell them, and your cable modem is not substituting its mac on the fly, then the server should see you as someone new and give you a vacant ip lease. – Matt Oct 16 '18 at 16:54
  • The problem was that it was giving me a vacant IP. And I was trying to force it to give me the one that was supposedly reserved, since the external DNS was pointing to that one! So, I sent the network admin the actual MAC address, and asked if he was really reserving an IP for that MAC. – Auspex Oct 17 '18 at 13:44
0

Normally, dhclient -r should do the trick; but if that doesn't work for you, I found a solution here:

+ Renew an IP address one time :

Note: In this example we will be using the interface eth0. The interface must be configured for DHCP as up and running.

  • Open a terminal and do sudo su to root.
  • Type ifconfig to show the current IP address that you received from DHCP.
  • Type dhcpcd -k to send the appropriate signals to dhcpcd (you might need to install dhcpcd by doing apt-get install dhcpcd).
  • Now bring the interface back up by typing ifup eth0.
  • Type ifconfig to show the new IP address.

There is also a section about renewing the IP address every-time, but the description was for RPM-based distros (in contrast to Debian-based distros like Ubuntu).

Hope it helps :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.