Potty Page

January 15, 2009

Hibernation, Wake-on-LAN and DHCP

At work and at home I have computers that can both do Wake-on-LAN (WOL). That means that I can turn them on over the LAN (and as the LANs are connected to the Internet, from the Internet). This is dead useful. I don't have to think... hmmm... I might need to access my computer remotely... I'd best leave it on anymore.

I also hibernate my computer in both places - that's another reason for leaving it on... everything is just as you left if when you want to use the computer again.

Furthermore, in both places the computer gets its IP address (and other info) by DHCP (dynamic host configuration protocol) - that means that things like it's IP address and what namesevers to use are all configured centrally on another computer somewhere, and when I turn on the computer it checks to see what settings to use.

OK. So why am I talking about this?

When you enable Windows to do all of these three things... that is Hibernation, WOL and DHCP, it does annoying things.

A bit more background... Basically, the information from the DHCP server expires - it goes out of date - and when this happens (well before this happens) the computer will ask the DHCP server for what the current configuration settings should be. Now, for a stable network this will be the same configuration all the time. The people administering the DHCP server will set how long the information is valid for - it's up to them to suggest how stable they see the settings. If it's stable they might have a DHCP lease time of a week or more... if it's unstable, maybe an hour or two.

At home I'm the admin, and I've decided that DHCP is valid for day. At work the admins have decided it's valid for two hours.

OK, so when the computer hibernates its clever and knows that as it's could have to WOL it needs to keep it's network configuration up-to-date. So, when it's half way between when it got the lease and when it expires it turns itself on, gets a DHCP update, and turns itself off again.

The thing is, for wake-on-lan to work you don't need to know the IP address of the computer you need to turn on - you only need to know the MAC address of the network card (as that's the only thing that's listening on the network and it's not really aware of any IP address, just its MAC address).

Now, in some situations knowledge of the IP address could be useful - as I'm sure that there are network management programs that can be used to turn on computers remotely that are linked into the DHCP servers (DHCP servers keep a table linking IP addresses on the network to MAC addresses on the network) - so if you've a big network, want to turn on a random computer and have no idea what the MAC address is, but know it's IP address then this might be the way to go. (this is pure speculation... such management programs may not exist!)

I however know the MAC addresses of both computers I want to turn on (and by using the magic of the /etc/ethers file in linux I've got a table of IP addresses and MAC addresses that my wakeonlan program knows about.)

So, what's the problem. Well... number one, my computer lives in my bedroom... and it turning on at 5am to refresh it's DHCP is far from ideal - secondly it doesn't turn itself off again for some reason.... and the computer at work turns itself on every hour (half of two) to update itself... given that it takes ages to go through the BIOS etc etc... it's actually on for about 5 mins every hour. What's worse... if you arrive at work when it's in the middle of a refresh and it's starting to shutdown again you have to wait for this shutdown and then turn it on again...

So, what are the solutions to this problem...

At home I'm the admin... so I've changed my entry on the DHCP tables (in dhcpd.conf) to something like...

host blueberry {
hardware ethernet 00:12:56:2b:4b:f9;
fixed-address 192.168.1.10;
default-lease-time 8640000;
max-lease-time 10000000;
}

Which sets the lease time to 100 days, meaning the computer will turn on to refresh every 50! As the computer seems to refresh its DHCP anyway when it comes out of hibernation I basically have to not turn my computer on in 50 days for it to be a problem.

So, what about at work? Where I'm not an admin of the network. Well, I could set my settings in statically. This would be bad - and cause annoyance to me - they've set the lease time to 2 hours for a reason - they could go changing DNS servers at random, the Internet would appear broken and I've have to manually correct them!

My solution was to install Hibernate Trigger. This is a little program that sits in your systray and waits for the computer to start hibernating - when it does it can run a program. It'll then also be waiting so that as soon as you come out of hibernation it runs another program.

So, I have two batch files. One for hibernation and one from resuming - the hibernation one simply runs ipconfig /release. This removes all the automatically set IP settings from my computer - this convinces it that it never has to turn on to update them. My resume script runs ipconfig /renew, this forces the configuration to be pulled from the server. I'm not strictly sure that the renew one is required - the DHCP might get automatically updated when you start the computer from hibernate anyway - but it's there for good measure, I've not tested it without.

Anyway, that's how (or at least the only way I could think of) to stop your computer waking from hibernation when you've enable Wake-on-LAN. This was after searching for an answer for a good few hours. Hopefully it'll help someone else!

Posted by Ed at January 15, 2009 11:04 PM | Geek |