Enable Wake-on-Lan (WoL)

Enable Wake-on-Lan (WoL)

Allow your server to be switched on remotely

Last updated:

linux ubuntu

Overview

Wake-on-Lan (WoL) enables you to turn on your machine remotely. This is ideal if you have machine in another room, like a server in an out of the way place. The machine wakes up when it receives a special message called a magic packet. You can send magic packets from other computers or even from your mobile phone. The message is sent over your network using Wi-Fi or a wired connection.

This article will show you how to enable WoL on your linux machine.

Enable BIOS Power Management Events

For Wake-on-Lan (WoL) to work the BIOS needs to be set to accept Power Management Events (PME). Different vendors might call have a different name for them, but in my Asus BIOS it was labelled Power on by PME.

List network Interfaces

To enable Wake-on-Lan (WoL) you need to find out what your Ethernet Interface is called. This is how your computer connects to your network.

You can use any one of the following methods:-

ip command

This shows or manipulate routing, devices, policy routing and tunnels.

ip link show

On my machine this outputs the following:-

1: lo: <loopback,up,lower_up> mtu 16436 qdisc noqueue state UNKNOWN
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <broadcast,multicast,up,lower_up> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:xx:yy:xx:yy:z0 brd ff:ff:ff:ff:ff:ff</broadcast,multicast,up,lower_up></loopback,up,lower_up>

In the shown output my first Interface is called eth0. If I had two Interfaces the second one would be called eth1, and so on. If I have Wi-Fi installed I might have an interface called wlan0.

netstat command

This diisplays network connections, routing tables, Interface statistics, masquerade connections, and multicast memberships.

netstat -i

On my machine this outputs the following:-

Kernel Interface table
Iface   MTU Met   RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
eth0       1500 0   6059317      0      0 0       3277643      0      0      0 BMRU
lo        16436 0        59      0      0 0            59      0      0      0 LRU

Again, in the shown output my first Interface is called eth0.

ifconfig command

This displays or configures a network Interface.

ifconfig -a

On my machine this outputs the following:-

eth0      Link encap:Ethernet  HWaddr 00:xx:yy:xx:yy:z0
          inet addr:134.111.0.1  Bcast:134.111.0.255  Mask:255.255.255.0
          inet6 addr: 00:xx:yy:xx:yy:z0/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6484950 errors:0 dropped:0 overruns:0 frame:0
          TX packets:3474044 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:8097099790 (8.0 GB)  TX bytes:1164269136 (1.1 GB)

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:16436  Metric:1
          RX packets:62 errors:0 dropped:0 overruns:0 frame:0
          TX packets:62 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:5008 (5.0 KB)  TX bytes:5008 (5.0 KB)&lt;/code&gt;&lt;/pre&gt;

Again finally, in the shown output my first Interface is called eth0.

Change Interface settings

Now that we know what our Interface is called, in my case eth0, we now need to install a program that can set or update settings on our Interface. The program to do this is called ethtool.

Install ethtool

sudo apt-get update
sudo apt-get install ethtool

This displays or sets Ethernet device settings.

Once ethtool has been installed you can now use the following command - replace eth0 with the name of your device.

sudo ethtool eth0

On my machine this outputs the following:

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/Half 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: 
        Current message level: 0x00000033 (51)
                               drv probe ifdown ifup
        Link detected: yes

The entry Supports Wake-on indicates whether your Interface supports Wake-on-Lan (WoL). The flag for WoL is g. In my example Supports Wake-on has a value of pumg, so my Interface does support Wake-on-Lan.

However, Wake-on currently has no value. So my Interface supports WoL but my Interface is not currently set to Wake-on-Lan (WoL).

Run the following command to enable Wake-on-Lan (WoL). Remember to replace eth0 with the name of your Interface.

sudo ethtool -s eth0 wol g

To see if WoL is now set, re-run this command:-

sudo ethtool eth0

You should now see that Wake-on is set to g.

Set WoL to work after reboot

When you restart your machine the Interface will forget the WoL setting. To make sure WoL is always set to g, we need to edit a script that runs every time the machine is turned on.

sudo nano /etc/network/Interfaces

On my machine this outputs the following:-

# This file describes the network Interfaces available on your system
# and how to activate them. For more information, see Interfaces(5).

# The loopback network Interface
auto lo
iface lo inet loopback

# The primary network Interface
auto eth0
iface eth0 inet dhcp

Add the following to the end of the file:-

#allow wol on boot
up ethtool -s eth0 wol g

To save a file opened using nano, do Ctrl + o to output the file and Ctrl + x to exit and return to the command line.

Testing Wake-on-Lan (WoL)

I use an app on my mobile phone called Fing that sends a WoL magic packet to my computer. I highly recommend this app.