How to enable and use Wake on LAN
In this article I will describe how to enable Wake-on-LAN (WOL) and how to use it to start-up a system remotely. In order to use Wake-on-LAN your systems hardware and network driver needs to actually support this technology. You will also need to know the MAC address of the systems ethernet card.
- Enable Wake-on-LAN
Enable Wake on LAN in BIOS. Sometimes the option is not addressed as “Wake-on-LAN”, but instead as “PCI Power up”, “OnBoard LAN Boot Rom” or similar.
- Find the network device
Boot into Linux and find out your Ethernet cards device name and MAC address by using this command:
$ ip link
or use this command:
My ethernet cards device name is eth0, so replace in all of the following commands eth0 by your cards device name.
- Check the drivers Wake-on-LAN support and settings
We will use the ethtool to check whether the network device and its driver support Wake-on-LAN and to activate it. Install ethtool from your distros repository or download it from here and then proceed like this:
$ sudo ethtool eth0 | grep Wake-on
Supports Wake-on: pg Wake-on: d
As you can see my device supports the wake on methods “p” and “g”. The meaning of these methods is described in the table below. Furthermore we can see that the “Wake-on” option is set to “d” (meaning disabled).
p Wake on PHY activity u Wake on unicast messages m Wake on multicast messages b Wake on broadcast messages a Wake on ARP g Wake on MagicPacket™ s Enable SecureOn™ password for MagicPacket™ d d Disable (wake on nothing).
source: ethtool man pages
- Change the drivers settings and shut down for the first test
Now we want to change the “Wake-on” method to “g”, which means that the system will wake up when it receives an MagicPacket™ addressed to its MAC address. You can do it like this:
$ sudo ethtool -s eth0 wol g
You may want to check if it successfully changed to “g” by using the command from step 3) again. If everything is alright shut down the system for the first test.
- Install a WOL-Software & start the target system remotely
Install a WOL-Software on any client you want to use to start-up the target system remotely. I installed wol. Install it from your distros package repository or download it from here. After installing wol try to start the target system remotely for the first time. Please notice that I didn’t provide the targets hostname by using the “-h HOSTNAME” option, because it leads to inconsistent behaviour. Replace “xx:xx:xx:xx:xx:xx” with the MAC address of your target system:
$ wol xx:xx:xx:xx:xx:xx
If everything went well the target system should be starting. In case you are not in the same local network as the target you have to also provide the port number and the external IP or Hostname of the target. Please take a look at the wol man pages for more details:
$ wol -p PORTNUM -i EXTERNAL_IP_OF_TARGET xx:xx:xx:xx:xx:xx
- Make the changes to the drivers settings persistent
You may have noticed that the Wake-on-LAN functionality only workes the first time. That’s because the driver resets the “Wake-on” option after each start of the system. In order to be able to always use wake on LAN, you have to set the drivers state every time the system boots back to “g”. Basically you just need to automatically execute the command from step 4) whenever your system starts up. For this purpose you may use any way that’s common or recommended in your Linux distro. In my case using a udev rule didn’t work and strangely with Systemd it only worked sometimes, but in the end a cronjob did the trick:
Create a new crontab for root like this
$ sudo crontab -e
an editor will open and insert this line:
@reboot /usr/bin/ethtool -s eth0 wol g
From now on the drivers state should be set to “g” on each boot and you should be able to always use wake on LAN.
Legal notice: image from wikimedia, released into the public domain
Posted on March 23, 2014, in Configure, Install, Network and tagged Bios, Boot, configuration, enable, ethernet, install, LAN, linux, linux command line, Linux M0nk3ys, Linux Monkeys, Magic Packet, network, OnBoard LAN Boot Rom, PCI Power up, remote, start up, use, Wake-on-LAN, WOL. Bookmark the permalink. 2 Comments.