lts is there a way to enable sleep mode and wake on lan?

I was wondering if it were posible to make my server go to sleep after a set period of time, but still be listening for lan requests. I use my server as a media server that might get used 3 or 4 hours a day and it is really a waste of power to have it running all the time. However I don’t want to run up to the second floor to switch it on when we want to watch a movie. I saw a few posts about stopping this from happening but how do you enable it?

Asked By: Craig Smith


Wake on LAN is a BIOS and NIC feature, not an OS feature, that is, you need a supporting BIOS and NIC to do it.

Once you’ve enabled it in your BIOS (if you can), you can check if your NIC has WOL support enabled by checking the output of ethtool [interface].

If the value of Supports Wake-on contains g, your NIC supports WOL magic packets.

To check if it is actually enabled, take a look at the value of Wake-on. If it contains g, your NIC has magic packet support enabled.

If it isn’t enabled, run the following:

ethtool -s [interface] wol g

You’ll have to issue this command every time your system starts, so add it to the appropriate place. In Ubuntu, perhaps the best place would be as an up rule in /etc/network/interfaces, or the equivalent for your network manager.

Answered By: Chris Down

I know this was asked a year ago, but I’ve found a few solutions. The first one uses powernap and a script to check for specific running processes, and can be found here.

Second I saw online was linux questions. This uses pings to another machine.

I also flashed a router with DD-WRT to try out- at the dd-wrt wiki. These are very nice elegant solutions but the issue I had with them is they are not suited for an internal media server, because the log only catches accepted packets from outside of the network. If you want an internal only media server this just doesn’t work.

For dd-wrt this offers a really nice solution to this using VLAN’s. Basically put the server on it’s own internal subnet and monitor traffic to that VLAN, then the previous script works. This works well, but in my experience the router and build of dd-wrt whenever I used the vlan feature DHCP crashed.

I decided I wanted a solution to wake and suspend my media server automatically when accessed that wasn’t dependent on dd-wrt. I have a raspberry pi so I used that. The final solution I found for myself was writing a little bash script.
The raspberry-pi dependencies are etherwake and tcpdump. Both are not installed by default on rasbian.

sudo apt-get install etherwake
sudo apt-get install tcpdump

The wake script is as follows:


pingInterval=60 #time interval, in seconds, between checks that the server is still awake.
target=192.168.x.x  #WOL target ip address
targetMAC=00:11:22:33:44:55  #WOL target MAC

wake () {
tcpdump -i eth0 -c 1 -p host $target
etherwake $targetMAC
#echo WOL sent to $target at $targetMAC

while sleep $pingInterval; do
varPing=`ping -s 1 -c 2 $target > /dev/null; echo $?`
if [ $varPing -eq 0 ]; then
#echo ping success
#echo ping fail

The primary idea is that it is run from my raspberry-pi which will wake the server if it notices a single arp request for the server. If the server is awake then it wont be listening for an arp request but send a few pings every now and then to make sure it is still awake.

I named the file and made it executable. Then put it in the sudo crontab to launch @reboot as root. This is for tcpdump which needs elevated access to listen to eth0 and etherwake.

sudo chmod +x /home/pi/
sudo crontab -e

add this to the bottom

@reboot sh /home/pi/ > /dev/null

The sleep script is run from the media server using the same principle. If there is no traffic to the server(excluding icmp or arp) during the interval of scanning I chose 1 minute. Then it adds to a counter which I named sleepiness. After the sleepiness reaches 10 or 20 meaning its had no traffic in and out for twenty minutes then it sets the sleepiness to zero then it issues the command pm-suspend to fall asleep. It packets are received and sleepiness!=0 then it does a sleepiness -1. So if it captures a stray packet or some how do you do’s from the router it won’t reset the count back to zero, but rather just do a -1 from the counter. I put this in there because it allows a grace period of gently falling to sleep as the packets decrease over a period of time rather than having absolutely zero packets for 20 consecutive minutes.

This is maybe not the best because it has to call tcpdump on both machines, Involves constant writes to disk (server side). For the writes to disk I mounted a sacrificial usb and that’s where my capture file is saved to prevent wear to my actual HDD.

Answered By: Travis Clark
Categories: Answers Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.