Did you ever try to remotely access your computer, maybe a server, only to realize that the machine is turned off? Or do you have a computer in the basement or a closet that you don’t want to run 24/7 and would like to conveniently power it on from anywhere in the world? There’s a solution for that called Wake-on-LAN (WoL). As the name suggests, it works by waking up the computer from a very low power state by sending a special message on the network. In this post, I will show you how to configure WoL on a computer running Ubuntu (it should also work with minor changes on other Linux flavors).
Step 1: Setup your server’s BIOS
First, enable Wake-on-LAN in your server’s BIOS. The option might be called something like
Power On by Onboard Lan. It is also possible that there’s no such option but that doesn’t mean that WoL is not supported. For example my Sun Ultra 24 workstation doesn’t have such an option in the BIOS but WoL works like a charm. This part was not necessary for my workstation.
Step 2: Find your network interface
ifconfig command to show all network interfaces:
$ifconfig -a eth0 Link encap:Ethernet HWaddr 02-bb-b9-5e-4d-ad inet addr:192.168.0.20 Bcast:192.168.0.255 Mask:255.255.255.0 inet6 addr: fe80::f66d:4ff:fe94:4dc6/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:24456 errors:0 dropped:8 overruns:0 frame:0 TX packets:19553 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:21270369 (21.2 MB) TX bytes:12700784 (12.7 MB) lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 inet6 addr: ::1/128 Scope:Host UP LOOPBACK RUNNING MTU:65536 Metric:1 RX packets:1524 errors:0 dropped:0 overruns:0 frame:0 TX packets:1524 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1 RX bytes:404601 (404.6 KB) TX bytes:404601 (404.6 KB)
In my case I only have two devices, the wired network interface eth0 and the loopback interface lo which the system uses to communicate with itself. I want to wake my server on eth0. On newer setups, the network interface might be called something like enp0s5. This is simply a new naming scheme for network interfaces. The highlighted line above shows the corresponding MAC address HWaddr 02-bb-b9-5e-4d-ad. This sequence uniquely identifies the network interface. Make note of the MAC address as you will need it later to wake up the computer.
Step 3: Set up the server software configuration
Now that you have identified the network interface, you need to enable WoL on your network interface using
ethtool. If not already pre-installed, install it using
sudo apt install ethtool.
To check if WoL is supported and if it is already enabled on the network interface, run
sudo ethtool <interface name>:
$sudo ethtool eth0 Settings for eth0: Supported ports: [ TP MII ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Half 1000baseT/Full Supported pause frame use: No Supports auto-negotiation: Yes Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Half 1000baseT/Full Advertised pause frame use: Symmetric Receive-only Advertised auto-negotiation: Yes Link partner advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full 1000baseT/Full Link partner advertised pause frame use: Symmetric Receive-only Link partner advertised auto-negotiation: Yes Speed: 1000Mb/s Duplex: Full Port: MII PHYAD: 0 Transceiver: internal Auto-negotiation: on Supports Wake-on: pumbg Wake-on: g Current message level: 0x00000033 (51) drv probe ifdown ifup Link detected: yes
The first highlighted line with the keyword
Wake-on shows the supported WoL options <code>pumbg</code>. The letter
g indicates that waking the system using a magic packet is supported. For all the other options, refer to the ethtool manual.
The second highlighted line shows the already enabled WoL options. As indicated by
Wake-on: g, WoL is already enabled on this system using magic packet. If this is not the case, WoL needs to be enabled with
sudo ethtool -s <interface name> wol g. However, this only temporarily enables WoL. To enable it permanently, add the line
pre-down /usr/sbin/ethtool -s <interface name> wol g to
auto eth0 iface eth0 inet static address 192.168.0.20 netmask 255.255.255.0 gateway 192.168.0.1 nameservers 192.168.0.1 126.96.36.199 pre-down /usr/sbin/ethtool -s eth0 wol g
In order to listen for a magic packet on the network interface, the network card must stay active after powering off the system. To keep the system from turning off completely, add
# Default behaviour of shutdown -h / halt. Set to "halt" or "poweroff". HALT=poweroff NETDOWN=no
Now that your system is configured for WoL, it is time to give it a try.
Step 4: Wake up the computer remotely
WoL works by sending a special message called the magic packet to all the machines on the network. The MAC address, as a unique identifier of the computer, is used to indicate which computer is to be woken up.
There are plenty of tools to send such wake up messages from another computer or even from a smartphone. I use the command-line tool
wakeonlan to wake up my server. You can install it with
sudo apt install wakeonlan.
To wake up your system, run
$wakeonlan <MAC address>:
$wakeonlan 02-bb-b9-5e-4d-ad Sending magic packet to 255.255.255.255:9 with 02-bb-b9-5e-4d-ad
You can also save the MAC address in a text file and run it using
$wakeonlan -f <file name>.
If your computer doesn’t power on after sending a magic packet, check the following things:
- MAC address: do you have the correct MAC address? Double-check using ifconfig -a.
- WoL enabled: is WoL permanently enabled? Reboot the server and check the output of
sudo ethtool <interface name>. If you don’t have the line
Wake-on: g, try repeating the commands from step 3.
- Network interface: is your network interface listening for a wake-up call when the system is turned off? Check the halt script
/etc/default/haltfor the option code>NETDOWN=no
If after all these steps WoL is still not working, it might be a hardware specific issue. Search for wake on lan and the name of your computer, main board or network card and you might just find a solution.