DHCP get back your old IP when you switch computer or network card

By: | Comments: No Comments

Posted in categories: Computer Tips, Work related

Modern DHCP server will identify clients using its MAC address, such that if you are offline (shutdown the client computer) for a short period, like a few hours, up to a few days, depends on the load of the dhcp server and the pool size, when you are back online again, you will get the same IP.

With this convenience, some services your computer provides that are bonded with IP won’t be unreachable after your reboot. However, when you have to upgrade your computer – motherboard, network adapter, or migrating the entire file system to a new computer, you get a new MAC, so that when you are online again, you will find that your get a different IP.

Usually it is not easy to negotiate with your network service provider to assign your old IP back – it may either just not negotiable, or take a long time or a fee.

However, there is a way to do it yourself – if you act fast – before the DHCP server has assigned the IP to a different computer – usually within a few days, you can get your old IP back for free.

Here is the steps (for Windows system):

0. First of all, you have to know your old IP – take a note of it, put it somewhere. In case you do not remember, and have no way to boot up your old computer to see it, you may try to find it from your remote desktop cache or remote log in cache, like ~/.ssh/known_hosts.
1. Make a linux live CD/DVD. The live CD/DVD images are downloadable for either a Fedora or Ubuntu mirror.
2. Boot your new system up using the live CD/DVD – of course you get a different IP. Do not worry. Here is the trick.
3. su –
This is to get the root privelege of the live OS.
4. dhclient -r
This is to release yourc current (wrong) IP. Now your computer will lost network connection. So do this before your monitor and keyboard, or through a IPMI, or your will lose contact with your computer.
5. cd /var/lib/dhclient
Here you will find a file named dhclient.leases which looks like this:
lease {
interface “em1”;
fixed-address xxx.xxx.xxx.xxx;
option subnet-mask 255.255.xxx.0;
option routers xxx.xxx.xxx.xxx;
option dhcp-lease-time 28800;
option dhcp-message-type 5;
option domain-name-servers xxx.xxx.xxx.xxx;
option dhcp-server-identifier xxx.xxx.xxx.xxx;
option domain-name “xxx.xxx.xxx”;
renew T yyyy/mm/dd hh:mm:ss;
rebind T yyyy/mm/dd hh:mm:ss;
expire T yyyy/mm/dd hh:mm:ss;
lease {
interface “em1”;
fixed-address XXX.XXX.XXX.XXX;
option subnet-mask 255.255.xxx.xxx;
option routers XXX.XXX.XXX.XXX;
option dhcp-lease-time 28800;
option dhcp-message-type 5;
option domain-name-servers XXX.XXX.XXX.XXX;
option dhcp-server-identifier XXX.XXX.XXX.XXX;
option domain-name “XXX.XXX.XXX”;
renew S yyyy/mm/dd hh:mm:ss;
rebind S yyyy/mm/dd hh:mm:ss;
expire S yyyy/mm/dd hh:mm:ss;
6. Now edit the file dhclient.leases, change the two lines of fixed-address back to your desired IP, then save. Better also copy this file to a safe place like your USB drive so that you won’t lost it, since the live OS won’t save any file for you.
7. Now run
dhclient -v
you will see that you get back your old IP – as long as the server has not assign it to anybody else.
8. Now you may shutdown the live OS, take out the CD/DVD, and boot up the Windows on the harddrive.
9. You should see that your windows gets back the old IP. And it will persist – won’t be lost after you reboot your windows.

If you are on a linux based system, you will only need step 3-7 and reboot. You do not need a live CD.

In the future, if you will need to do this again, you can always find out the dhclient.leases file out of your USB drive (if you have saved in step 6) and copy it back to the /var/lib/dhclient location after a dhclient -r, and do dhclient -v to get the IP back.

Be the first to comment!

Leave a Reply