Wednesday, January 18, 2012

Forcing Ubuntu 10.0.4 to renew a DHCP client after hibernate/sleep mode...

If you're on a network that has a short DHCP lease and your Ubuntu machine suspends/hibernates, you may find that you often may be IP conflicting with another system on the same network. You can run /etc/init.d/networking but often times you just want to force the DHCP renewal yourself.

One way is to modify /etc/default/acpi-support and add the "networking" module to the STOP_SERVICES declaration for the /etc/default/acpi-support file. However, if you have multiple networking interfaces that need to be restarted on bootup, this could cause more delays after resuming. It also seems strange that you have to taken down an entire networking module just to get things working again.

Another approach is to execute dhclient -r after resuming. As of Ubuntu 10.04, the power management modules actually use pm-utils, though there is a legacy /etc/acpi/ directory that often invokes pm-sleep, pm-hibernate and setups events depending on laptop keys pressed. You can find learn how to write your own power management hooks.

Here's how I got things to work:

1. sudo vi /etc/pm/sleep.d/00_network
#!/bin/bash
case $1 in
hibernate)
echo "Hey guy, we are going to suspend to disk!"
;;
suspend)
echo "Oh, this time we are doing a suspend to RAM. Cool!"
;;
thaw)
/sbin/dhclient -r
/sbin/dhclient
;;
resume)
/sbin/dhclient -r
/sbin/dhclient
;;
*) echo "Somebody is calling me totally wrong."
;;
esac
2. sudo chown root /etc/pm/sleep.d/00_network

To test, run sudo pm-sleep or sudo pm-hibernate. On bootup, take a look at tail -30 /var/log/pm-suspend.log and see if you see the 00_network script resume. If so, you should be good to go!

/etc/pm/sleep.d/00_network thaw hibernate:Internet Systems Consortium DHCP Client V3.1.3
Copyright 2004-2009 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/


No comments:

Post a Comment