How can I renew or release a Dynamic IP address in Linux?
The DHCP client in Linux is called dhclient. It requests dynamic IP addresses from the DHCP server, which "leases" addresses to clients for a set amount of time. dhclient can be invoked manually to "release" the client's currently assigned IP address, and get another address from the DHCP server.
Normally, dhclient produces no output, to see what it's doing, we need to give it the -v (verbose) option. We also need to run dhclient as root with the sudo command, because changing the system networking configuration requires escalated privileges.
Let's start by running dhclient verbosely, without any other options. It should reach out and say "hello" to our DHCP server, which, in this case, is a simple home router.
sudo dhclient -v
Internet Systems Consortium DHCP Client 4.2.2 Copyright 2004-2011 Internet Systems Consortium. All rights reserved. For info, please visit https://www.isc.org/software/dhcp/ Listening on LPF/wlan0/68:a3:c4:93:47:46 Sending on LPF/wlan0/68:a3:c4:93:47:46 Sending on Socket/fallback DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 4 DHCPREQUEST on wlan0 to 255.255.255.255 port 67 DHCPOFFER from 192.168.2.1 DHCPACK from 192.168.2.1 RTNETLINK answers: File exists bound to 192.168.2.4 -- renewal in 42516 seconds.
The above output tells us that dhclient requested an address from the DHCP server (DHCPREQUEST). It sent this request from our wireless internet interface (wlan0). The DHCP server responded with a simple acknowledgement of our request (DHCPACK). In this case, that's just about all that happened, because we already had an IP address assigned to us, so the DHCP server didn't have anything to do. Note that the DHCP server also told us how long our dynamic IP address will last: 42516 seconds (about 12 hours from now, at which point it will be renewed automatically).
So let's manually release our address with -r. Let's keep the -v option in there so we can see what's going on:
sudo dhclient -v -r
Internet Systems Consortium DHCP Client 4.2.2 Copyright 2004-2011 Internet Systems Consortium. All rights reserved. For info, please visit https://www.isc.org/software/dhcp/ Listening on LPF/wlan0/68:a3:c4:93:47:46 Sending on LPF/wlan0/68:a3:c4:93:47:46 Sending on Socket/fallback DHCPRELEASE on wlan0 to 192.168.2.1 port 67
In the above example, the command tells the DHCP server to release the IP address.
Warning: On some variants of Linux or Unix, releasing your IP address this way may also inherently bring down your network interface. In this case, use your network manager to re-connect to your network. This process varies from OS to OS; if you're not sure how to connect to your network, consult the documentation of your specific OS. If you're using the X Window System, it depends on your window manager, but you can usually reconnect by clicking on the network icon in your system tray, and selecting the Connect option.