How to renew dhcp ip address in ubuntu?

66,490

Solution 1

This is simple:

$ dhclient -r    #release current address
$ dhclient eth0  #ask for new address

Solution 2

Actually, there are (somewhat unusual) situations in which

$ dhclient -r
$ dhclient

is not sufficient.

If the client thinks it already has a valid lease, it will use it, even if the DHCP server would have given it a different address. This can be confusing.

For instance, if you go from a dynamically allocated IP address to a static (and different) IP address for a given client, then (at least on Ubuntu 10.04, and possibly generally) $dhclient -r and $dhclient isn't sufficient. Because the old lease is still valid, the client will just use that.

This can lead to your DHCP server thinking the IP address for your host should be one thing, and your host thinking a different thing. Chaos reigns.

To fix this, you first have to go and delete any dhclient.leases files from /var/lib/dhcpd/ (or /var/lib/dhcp3), where the client stores its valid leases.

Then

$ dhclient -r
$ rm /var/lib/dhcp/dhclient*    # might be in a different place on your machine
$ dhclient

will fetch you a new, different address.

Solution 3

dhclient should do it.

Share:
66,490

Related videos on Youtube

elviejo79
Author by

elviejo79

I’m a software developer, CS teacher and Entrepreneur with experience creating small tech companies. I love leading small focused teams to achieve success and I also love teaching introduction to programming to high school, college and graduated students.

Updated on July 19, 2022

Comments

  • elviejo79
    elviejo79 about 6 hours

    This is a simple question in ubuntu server How do I renew a dhcp assigned IP address?

    • Zypher
      Zypher over 12 years
      Why are you running DHCP for server addressing?
    • elviejo79
      elviejo79 over 12 years
      @Zypher I'm setting up ubuntu-server in a virtualBox virtual machine, so it needs to get the ipaddress everytime I turn it on.
  • Rook
    Rook over 12 years
    sudo dhclient always works, it doesn't need an argument but you can give it one.