HOW-TO:Set up Wake-on-LAN for Ubuntu
Before you start
First off, the motherboard should support the WOL (Wake On LAN) and it should be enabled in the BIOS. Different BIOS/motherboard do it differently; on ASUS (P5N7A-VM), it's under Power > APM Configuration and in there "Resume On PCIE Wake" and "Resume On LAN(MAC)" should be enabled.
Enabling WOL in the OS
Even though WOL works in network layer 2, OS support is still one of the important things to make it work. Even if you see the light on the Ethernet port is on after the halt/shutdown, the OS shuts off the Ethernet internally. One must tell Ethernet controller to WOL when boots up and tell "halt" script not to bring down controller during shut-down.
Install ethtool
I found "ethtool" is one of the easiest to use to enable WOL; install it first if it's not there yet.
sudo apt-get ethtool
Set Wake-on-LAN options
Run the following command to enable it:
sudo ethtool -s eth0 wol g
- Note: Not all devices support this.
This can be verified running ethtool on ethX (where X is the name/number of the Ethernet device).
xbmc@htpc:~$ sudo ethtool eth0 [sudo] password for xbmc: Settings for eth0: Supported ports: [ MII ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full ..... ..... Auto-negotiation: on Supports Wake-on: g Wake-on: g Link detected: yes
Get it enabled at system start-up
Debian/Ubuntu uses Sys-V like init system for executing commands during the system bootup and shutdown time. If you wish to add a new service to start when the machine boots the script should be added to the directory /etc/init.d/ and then the "/etc/rc{runlevel}.d/" symlinks cause the script to be executed.
The init.d script
Create a file, say "walk-on-lan" in the "/etc/init.d/" (just copy & paste the entire code in the terminal)
sudo cat << EOF >> /etc/init.d/walk-on-lan #!/bin/bash # ### BEGIN INIT INFO # Provides: walk-on-lan # Required-Start: \$local_fs # Required-Stop: \$local_fs # Default-Start: 2 3 4 5 # Default-Stop: 0 6 # Short-Description: Enable Wake-On-Lan ### END INIT INFO # . /lib/lsb/init-functions do_start() { ethtool -s eth0 wol g exit } do_stop() { ethtool -s eth0 wol d exit } case "$1" in start) do_start ;; restart|reload|force-reload) echo "Error: argument '$1' not supported" >&2 exit 3 ;; stop) do_stop ;; *) echo "Usage: $0 start|stop" >&2 exit 3 ;; esac EOF sudo chmod 755 /etc/init.d/walk-on-lan
Start the service upon boot
"sysv-rc-conf" is Run-level configuration for Sys-V like init script links. From the man page: sysv-rc-conf gives an easy to use interface for managing "/etc/rc{runlevel}.d/" symlinks. sysv-rc-conf is not installed by default and needs to be installed.
sudo apt-get install sysv-rc-conf
and then
sudo sysv-rc-conf --level 2345 walk-on-lan on