Difference between revisions of "Wake-on-LAN"

From ArchWiki
Jump to navigation Jump to search
(In all situations: changed wording, since wol moved from AUR to [community])
(udev: the purpose of this section is not about udev rules in initramfs, additionally the comment is unclear, no feedback neither from discussion after 1 week - removed)
 
(238 intermediate revisions by 71 users not shown)
Line 1: Line 1:
[[Category:Network]]
+
[[Category:Networking]]
 +
[[ja:Wake-on-LAN]]
 +
[[Wikipedia:Wake-on-LAN|Wake-on-LAN]] (WoL) is a feature to switch on a computer via the network.
  
This article deals with Wake-on-LAN (wol, wake on lan), what it is, how it can be used from an Arch Linux computer, and its general uses.
+
== Hardware settings ==
  
=What is Wake-on-LAN?=
+
The target computer's motherboard and [[wikipedia:Network interface controller|Network Interface Controller]] have to support Wake-on-LAN. The target computer has to be physically connected (with a cable) to a router or to the source computer, wireless cards do not support WoL.
  
Basically put, Wake-on-LAN, otherwise known as 'wol' is the ability to switch a computer that is connected to a network (be it the internet or intranet) on. This can be a very useful ability.
+
The Wake-on-LAN feature also has to be enabled in the computer's BIOS. Different motherboard manufacturers use slightly different language for this feature. Look for terminology such as "PCI Power up", "Allow PCI wake up event" or "Boot from PCI/PCI-E".
  
It is important to note that Wake-on-LAN applies to the computers being physically connected (ie, not wireless).
+
Note that some motherboards are affected by a bug that can cause immediate or random [[#Wake-up after shutdown]] whenever the BIOS WoL feature is enabled.
  
==Does my motherboard support Wake-on-LAN?==
+
== Software configuration ==
  
For Wake-on-LAN to work, the target computer motherboard must support this feature. Generally speaking, the Wake-on-LAN (non)ability of the target motherboard will be specified by the hardware manufacturer. Sometimes, this ability is evident by browsing through said motherboard's BIOS and looking for something like 'PCI Power  up'. Most modern motherboards should support Wake-on-LAN.
+
=== Enable WoL on the network adapter ===
  
==Wake-on-LAN in different situations==
+
Depending on the hardware, the network driver may have WoL switched off by default.
  
The computer that you want to use Wake-on-LAN on may be directly linked to your computer through a network cable, connected to the same router that you are using, or remotely, across the internet.
+
To query this status or to change the settings, install {{Pkg|ethtool}}, determine the name of the [[network interface]], and query it using the command:
  
===In all situations===
+
{{hc|# ethtool ''interface'' {{!}} grep Wake-on|
 +
Supports Wake-on: pumbag
 +
Wake-on: d}}
 +
The ''Wake-on'' values define what activity triggers wake up: {{ic|d}} (disabled), {{ic|p}} (PHY activity), {{ic|u}} (unicast activity), {{ic|m}} (multicast activity), {{ic|b}} (broadcast activity), {{ic|a}} (ARP activity), and {{ic|g}} (magic packet activity). The value {{ic|g}} is required for WoL to work, if not, the following command enables the WoL feature in the driver:
  
There are four essential things needed in order to use Wake-on-LAN on a target PC:
+
# ethtool -s ''interface'' wol g
  
#Some kind of Wake-on-LAN software on the host (your) PC
+
{{Note|Setting one of {{ic|u}}, {{ic|m}} or {{ic|b}} along with {{ic|g}} might also be necessary to enable the feature.}}
#A connection to the internet or intranet of the target PC
 
#The MAC address of the target PC
 
#The internal or external IP of the target PC
 
  
*Firstly, install a Wake-on-LAN software. In this article, [http://ahh.sourceforge.net/wol/ wol] will be used. It can be installed from the [[AUR_User_Guidelines#.5Bcommunity.5D|[community]]] repository.
+
This command might not last beyond the next reboot and in this case must be repeated via some mechanism. Common solutions are listed in the following subsections.
  
*'''It is recommended that you read the documentation of wol'''
+
=== Make it persistent ===
  
man wol
+
==== systemd.link ====
wol --help
 
  
*wol requires several parameters, the most basic needed:
+
Link-level configuration is possible through [[systemd-networkd#link files]]. The actual setup is performed by the {{ic|net_setup_link}} udev builtin. Add the {{ic|WakeOnLan}} option to the network link file:
  
wol MACADDRESS
+
{{hc|/etc/systemd/network/50-wired.link|2=
 +
[Match]
 +
MACAddress=''aa:bb:cc:dd:ee:ff''
  
*But it is good practice to include the IP address or hostname, therefore this syntax should be the minimal used:
+
[Link]
 +
NamePolicy=kernel database onboard slot path
 +
MACAddressPolicy=persistent
 +
'''WakeOnLan=magic'''}}
 +
Also see {{man|5|systemd.link}} for more information.
 +
{{Note|
 +
* This configuration applies only to the link-level, and is independent of network-level daemons such as [[NetworkManager]] or [[systemd-networkd]].
 +
* To be considered, the file name should alphabetically come before the default {{ic|99-default.link}} link file shipped with systemd. For example {{ic|50-wired.link}} works.
 +
* In the {{ic|Match}} section, {{ic|1=OriginalName=}} can also be used to identify the interface.}}
  
wol -i HOSTNAME_OR_IP MACADDRESS
+
==== systemd service ====
  
*The documentation of wol states that:
+
This is an equivalent of previous {{ic|systemd.link}} option, but uses a standalone systemd service.
  
::''Each MAC-ADDRESS is written as x:x:x:x:x:x, where x is a hexadecimal number between 0 and ff which represents one byte of the address, which is in network byte order (big endian).''
+
{{hc|/etc/systemd/system/wol@.service|2=
 +
[Unit]
 +
Description=Wake-on-LAN for %i
 +
Requires=network.target
 +
After=network.target
  
*To obtain the MACADDRESS of the target computer:
+
[Service]
 +
ExecStart=/usr/bin/ethtool -s %i wol g
 +
Type=oneshot
  
ifconfig | grep HWaddr
+
[Install]
 +
WantedBy=multi-user.target
 +
}}
  
The port, IP or hostname of the target PC will be addressed in the relevant following sections.
+
Alternatively install the {{AUR|wol-systemd}} package, then activate this new service by [[starting]] {{ic|wol@''interface''.service}}.
  
===Across your intranet/network (no router)===
+
==== udev ====
  
If you are connected directly to another computer through a network cable, or have disabled your router firewall (not a good idea), then using Wake-on-LAN should be very simple.
+
[[udev]] is capable of running any command as soon as a device is visible. The following rule will turn on WOL on all [[network interface]]s whose name matches {{ic|enp*}}. The file name is important and must start with a number between 81 and 99 so that it runs '''after''' {{ic|80-net-setup-link.rules}}, which renames interfaces with predicable names. Otherwise, {{ic|NAME}} would be undefined and the rule would not run.
  
====For two computers connected to each other====
+
{{hc|/etc/udev/rules.d/'''81'''-wol.rules|2=
 +
ACTION=="add", SUBSYSTEM=="net", NAME=="enp*", RUN+="/usr/bin/ethtool -s $name wol g"
 +
}}
  
wol MACADDRESS_OF_TARGET_PC
+
The {{ic|$name}} placeholder will be replaced by the value of the {{ic|NAME}} variable for the matched device.
  
====For computers connected to a non-firewalled router====
+
==== cron ====
  
wol -i INTERNAL_IP_OF_TARGET_PC MACADDRESS_OF_TARGET_PC
+
A command can be run each time the computer is (re)booted using "@reboot" in a crontab. First, make sure [[Cron#Installation|cron]] is enabled, and then [[Cron#Basic_commands|edit a crontab]] for the root user that contains the following line:
  
*To find the internal IP (it's the first grepped entry):
+
@reboot /usr/bin/ethtool -s ''interface'' wol g
  
ifconfig | grep 'inet addr'
+
==== netctl ====
  
*Since you are not firewalled, then there is no need to worry about port redirects.
+
If using [[netctl]], one can make this setting persistent by adding the following the netctl profile:
*If you intend to continue using Wake-on-LAN, it is recommended that you assign your computer's MACADDRESS to a specific IP on your router. Consult your router for details as to how to do this.
 
  
===Across your intranet/network (router)===
+
{{hc|/etc/netctl/''profile''|2=
 +
ExecUpPost='/usr/bin/ethtool -s ''interface'' wol g'
 +
}}
  
The syntax used in this situation:
+
==== NetworkManager ====
 +
NetworkManager provides [https://www.phoronix.com/scan.php?page=news_item&px=NetworkManager-WoL-Control Wake-on-LAN ethernet support]. One way to enable Wake-on-LAN by magic packet is through ''nmcli''.
  
wol -p PORT_FORWARDED_TO_INTERNAL_IP -i INTERNAL_IP MACADDRESS_OF_TARGET_PC
+
First, search for the name of the wired connection:
  
*When you send the MagicPacket signal to the target computer via a specific port, the signal passes through your router. The router must be instructed to forward any signal heading for that specific port to the internal IP of the target PC.
+
{{hc|# nmcli con show|2=
 +
NAME    UUID                                  TYPE            DEVICE
 +
wired1  612e300a-c047-4adb-91e2-12ea7bfe214e  802-3-ethernet  enp0s25
 +
}}
  
*It is recommended that for multiple computers connected to one computer, to assign a different port forward to each internal IP
+
By following, one can view current status of Wake-on-LAN settings:
  
*For port forwarding help, please consult http://portforward.com/ (though this website has some Windows specific content, it has a very large database of router web interfaces)
+
{{hc|# nmcli c show "wired1" <nowiki>|</nowiki> grep 802-3-ethernet.wake-on-lan|2=
 +
802-3-ethernet.wake-on-lan:             default
 +
802-3-ethernet.wake-on-lan-password:    --
 +
}}
  
===Across the internet===
+
Enable Wake-on-LAN by magic packet on that connection:
  
The syntax needed in this case:
+
# nmcli c modify "wired1" 802-3-ethernet.wake-on-lan magic
  
wol -p X -i HOSTNAME_OR_EXTERNAL_IP_OF_TARGET MACADDRESS
+
Then reboot, possibly two times. To disable Wake-on-Lan, substitute {{ic|magic}} with {{ic|ignore}}.
  
*Assuming that you know the external IP of the target machine, and that the [[Wake-on-LAN#Across_your_intranet.2Fnetwork_.28router.29|router ports]] on both sides have been forwarding correctly, then this should be exactly as the syntax states.
+
The Wake-on-LAN settings can also be changed from the GUI using {{Pkg|nm-connection-editor}}.
  
==Additional Notes==
+
=== Enable WoL in TLP ===
  
A common problem with the Wake-on-LAN in computers running linux is that the network drivers have Wake-on-LAN switched off by default.
+
When using [[TLP]] for suspend/hibernate, the {{ic|WOL_DISABLE}} setting should be set to {{ic|N}} in {{ic|/etc/default/tlp}} to allow resuming the computer with WoL.
  
*To manually switch on the Wake-on-LAN feature on your driver, you'll need ethtool:
+
== Trigger a wake up ==
pacman -Sy ethtool
+
To trigger WoL on a target machine, its '''MAC address''' must be known.
ethtool -s ethX wol ubmg
+
To obtain it, execute the following command from the machine:
 +
{{hc|$ ip link|
 +
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
 +
  link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
 +
2: enp1s0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UP group default qlen 1000
 +
    link/ether '''48:05:ca:09:0e:6a''' brd ff:ff:ff:ff:ff:ff}}
  
*This command does not last beyond the next reboot. To execute the command everytime you start up your computer, add the command into /etc/rc.local
+
Here the MAC address is {{ic|48:05:ca:09:0e:6a}}.
  
*For more information on this, please read the [http://ahh.sourceforge.net/wol/faq.html wol FAQ] (not available at the moment - 11/12/2008)
+
In its simplest form, Wake-on-LAN broadcasts the magic packet containing the MAC address within the current network subnet, below the IP protocol layer. The knowledge of an IP address for the target computer is not necessary.
  
*If for some reason, you find that after using the command to switch your network drivers Wake-on-LAN feature on, the computer shuts down normally but then starts again, experiment with combinations of [u/b/m]g
+
If used to wake up a computer over the internet or in a different subnet, it typically relies on the router to relay the packet and broadcast it.
 +
In this scenario, the external IP address of the router must be known and in some cases the internal IP address of the target machine is needed to ensure the NAT (Network Address Translator) router manages to communicate with the target machine.
  
*Another problem is that a lot of people forget to switch on the Wake-on-LAN feature in their BIOS.
+
Applications that are able to send magic packets for Wake-on-LAN:
 +
* {{App|gWakeOnLAN|GTK+ utility to awake turned off computers through the Wake-on-LAN feature.|https://muflone.com/gwakeonlan/english/|{{Pkg|gwakeonlan}}}}
 +
* {{App|wol|Implements Wake-on-LAN functionality in a small program. It wakes up hardware that is Magic Packet compliant.|https://sourceforge.net/projects/wake-on-lan/|{{Pkg|wol}}}}
  
*In some systems the BIOS option "Boot from PCI/PCI-E" needs to be Enabled.
+
=== On the same LAN ===
 +
 
 +
If you are connected directly to another computer through a network cable, or the traffic within a LAN is not firewalled, then using Wake-on-LAN should be straightforward since there is no need to worry about port redirects.
 +
 
 +
In the simplest case the default broadcast address {{ic|255.255.255.255}} is used:
 +
 
 +
$ wol ''target_MAC_address''
 +
 
 +
To broadcast the magic packet only to a specific subnet or host, use the {{ic|-i}} switch:
 +
 
 +
$ wol -i ''target_IP'' ''target_MAC_address''
 +
 
 +
=== Across the internet ===
 +
 
 +
When the source and target computers are separated by a NAT router, different solution can be envisaged:
 +
* If the router supports ''WoL'', one can rely on it to properly broadcast the packet into the local network.
 +
 
 +
Otherwise Wake-on-Lan can be achieved via [[wikipedia:Port forwarding|port forwarding]]. The router needs to be configured using one of these two options:
 +
 
 +
* Forward a different port to each target machine. This requires any target machine to have a static IP address on its LAN.
 +
* Forward a single port to the [[wikipedia:Broadcast_address|broadcast address]]. Most routers do not allow to forward to broadcast, however if you can get shell access to your router, through telnet, ssh, serial cable or other mean, run the command: {{bc|$ ip neighbor add 192.168.1.254 lladdr FF:FF:FF:FF:FF:FF dev net0}} This example assumes the network is ''192.168.1.0/24'' and uses ''net0'' as network interface. Now, forward UDP port 9 to 192.168.1.254. This solution was successfully tested on a Linksys WRT54G running [[Wikipedia:Tomato_(firmware)|Tomato]], and on the Verizon FIOS ActionTec router. For notes on how to do it on a router with [[Wikipedia:DD-WRT|DD-WRT]] firmware, see [http://www.dd-wrt.com/wiki/index.php/WOL#Remote_Wake_On_LAN_via_Port_Forwarding this tutorial] and for a router with [[Wikipedia:OpenWrt|OpenWrt]] firmware, see [https://wiki.openwrt.org/doc/uci/wol this tutorial].
 +
 
 +
In any case, run the following command from the source computer to trigger wake-up:
 +
 
 +
$ wol -p ''forwarded_port'' -i ''router_IP'' ''target_MAC_address''
 +
 
 +
== Miscellaneous ==
 +
 
 +
=== Check reception of the magic packets ===
 +
In order to make sure the WoL packets reach the target computer, one can listen to the UDP port, usually port 9, for magic packets.
 +
The magic packet frame expected contains 6 bytes of FF followed by 16 repetitions of the target computer's MAC (6 bytes each) for a total of 102 bytes.
 +
 
 +
==== Using netcat ====
 +
This can be performed by installing {{pkg|gnu-netcat}} on the target computer and using the following command:
 +
 
 +
# nc --udp --listen --local-port=9 --hexdump
 +
 
 +
Then wait for the incoming traffic to appear in the {{ic|nc}} terminal.
 +
 
 +
==== Using ngrep ====
 +
Install {{pkg|ngrep}} on the target computer and type the following command:
 +
 
 +
# ngrep '\xff{6}(.{6})\1{15}' -x port 9
 +
 
 +
=== Example of WoL script ===
 +
Here is a script that illustrates the use of {{ic|wol}} with different machines:
 +
{{bc|<nowiki>
 +
#!/bin/bash
 +
 
 +
# definition of MAC addresses
 +
monster=01:12:46:82:ab:4f
 +
ghost=01:1a:d2:56:6b:e6
 +
 
 +
echo "Which PC to wake?"
 +
echo "m) monster"
 +
echo "g) ghost"
 +
echo "q) quit"
 +
read input1
 +
case $input1 in
 +
  m)
 +
    /usr/bin/wol $monster
 +
    ;;
 +
  g)
 +
    # uses wol over the internet provided that port 9 is forwarded to ghost on ghost's router
 +
    /usr/bin/wol --port=9 --host=ghost.mydomain.org $ghost
 +
    ;;
 +
  Q|q)
 +
    break
 +
    ;;
 +
esac</nowiki>}}
 +
 
 +
== Troubleshooting ==
 +
 
 +
=== Wake-up after shutdown ===
 +
It is known that some motherboards are affected by a bug that can cause immediate or random wake-up after a ''shutdown'' whenever the BIOS WoL feature is enabled (as discussed in [https://bbs.archlinux.org/viewtopic.php?id=173648 this thread] for example). The following actions in the BIOS preferences can solve this issue with some motherboards:
 +
# Disable all references to ''xHCI'' in the USB settings (note this will also disable USB 3.0 at boot time)
 +
# Disable ''EuP 2013'' if it is explicitly an option
 +
# Optionally enable wake-up on keyboard actions
 +
{{Note|There are mixed opinions as to the value of #3 above and it may be motherboard dependent.}}
 +
 
 +
=== Battery draining problem ===
 +
Some laptops have a battery draining problem after shutdown [http://ubuntuforums.org/archive/index.php/t-1729782.html]. This might be caused by enabled WOL. To solve this problem, disable it by using ethtool as mentioned above.
 +
 
 +
# ethtool -s net0 wol d
 +
 
 +
=== Realtek ===
 +
 
 +
Users with Realtek 8168 8169 8101 8111(C) based NICs (cards / and on-board) may notice a problem where the NIC seems to be disabled on boot and has no Link light. See [[Network configuration#Realtek no link / WOL problem]].
 +
 
 +
If the link light on the network switch is enabled when the computer is turned off but wake on LAN is still not working, booting the system using the {{Pkg|r8168}} kernel module at least once and then switching back to the r8169 kernel module included with the kernel seems to fix it at least in the following configurations:
 +
* MSI B85M-E45 motherboard, BIOS version V10.9, onboard Realtek 8111G chipset
 +
 
 +
For the {{ic|r8168}} module you might need to set the {{ic|1=s5wol=1}} [[Kernel_modules#Setting_module_options|module option]] to enable the wake on LAN functionality.
 +
 
 +
===alx driver support===
 +
 
 +
For some newer Atheros-based NICs (such as Atheros AR8161 and Killer E2500), WOL support has been disabled in the mainline {{ic|alx}} module due to a bug causing unintentional wake-up (see [http://www.spinics.net/lists/netdev/msg242477.html this patch discussion]). A patch can be applied (or installed as a [[dkms]] module) which both restores WOL support and fixes the underlying bug, as outlined in [https://bugzilla.kernel.org/show_bug.cgi?id=61651 this thread].
 +
 
 +
See also the pre-patched sources in [https://github.com/Snugface/alx].
 +
 
 +
== See also ==
 +
 
 +
* [http://www.depicus.com/wake-on-lan/woli.aspx Wake-On-Lan]

Latest revision as of 17:09, 9 February 2019

Wake-on-LAN (WoL) is a feature to switch on a computer via the network.

Hardware settings

The target computer's motherboard and Network Interface Controller have to support Wake-on-LAN. The target computer has to be physically connected (with a cable) to a router or to the source computer, wireless cards do not support WoL.

The Wake-on-LAN feature also has to be enabled in the computer's BIOS. Different motherboard manufacturers use slightly different language for this feature. Look for terminology such as "PCI Power up", "Allow PCI wake up event" or "Boot from PCI/PCI-E".

Note that some motherboards are affected by a bug that can cause immediate or random #Wake-up after shutdown whenever the BIOS WoL feature is enabled.

Software configuration

Enable WoL on the network adapter

Depending on the hardware, the network driver may have WoL switched off by default.

To query this status or to change the settings, install ethtool, determine the name of the network interface, and query it using the command:

# ethtool interface | grep Wake-on
Supports Wake-on: pumbag
Wake-on: d

The Wake-on values define what activity triggers wake up: d (disabled), p (PHY activity), u (unicast activity), m (multicast activity), b (broadcast activity), a (ARP activity), and g (magic packet activity). The value g is required for WoL to work, if not, the following command enables the WoL feature in the driver:

# ethtool -s interface wol g
Note: Setting one of u, m or b along with g might also be necessary to enable the feature.

This command might not last beyond the next reboot and in this case must be repeated via some mechanism. Common solutions are listed in the following subsections.

Make it persistent

systemd.link

Link-level configuration is possible through systemd-networkd#link files. The actual setup is performed by the net_setup_link udev builtin. Add the WakeOnLan option to the network link file:

/etc/systemd/network/50-wired.link
[Match]
MACAddress=aa:bb:cc:dd:ee:ff

[Link]
NamePolicy=kernel database onboard slot path
MACAddressPolicy=persistent
WakeOnLan=magic

Also see systemd.link(5) for more information.

Note:
  • This configuration applies only to the link-level, and is independent of network-level daemons such as NetworkManager or systemd-networkd.
  • To be considered, the file name should alphabetically come before the default 99-default.link link file shipped with systemd. For example 50-wired.link works.
  • In the Match section, OriginalName= can also be used to identify the interface.

systemd service

This is an equivalent of previous systemd.link option, but uses a standalone systemd service.

/etc/systemd/system/wol@.service
[Unit]
Description=Wake-on-LAN for %i
Requires=network.target
After=network.target

[Service]
ExecStart=/usr/bin/ethtool -s %i wol g
Type=oneshot

[Install]
WantedBy=multi-user.target

Alternatively install the wol-systemdAUR package, then activate this new service by starting wol@interface.service.

udev

udev is capable of running any command as soon as a device is visible. The following rule will turn on WOL on all network interfaces whose name matches enp*. The file name is important and must start with a number between 81 and 99 so that it runs after 80-net-setup-link.rules, which renames interfaces with predicable names. Otherwise, NAME would be undefined and the rule would not run.

/etc/udev/rules.d/81-wol.rules
ACTION=="add", SUBSYSTEM=="net", NAME=="enp*", RUN+="/usr/bin/ethtool -s $name wol g"

The $name placeholder will be replaced by the value of the NAME variable for the matched device.

cron

A command can be run each time the computer is (re)booted using "@reboot" in a crontab. First, make sure cron is enabled, and then edit a crontab for the root user that contains the following line:

@reboot /usr/bin/ethtool -s interface wol g

netctl

If using netctl, one can make this setting persistent by adding the following the netctl profile:

/etc/netctl/profile
ExecUpPost='/usr/bin/ethtool -s interface wol g'

NetworkManager

NetworkManager provides Wake-on-LAN ethernet support. One way to enable Wake-on-LAN by magic packet is through nmcli.

First, search for the name of the wired connection:

# nmcli con show
NAME    UUID                                  TYPE            DEVICE
wired1  612e300a-c047-4adb-91e2-12ea7bfe214e  802-3-ethernet  enp0s25

By following, one can view current status of Wake-on-LAN settings:

# nmcli c show "wired1" | grep 802-3-ethernet.wake-on-lan
802-3-ethernet.wake-on-lan:             default
802-3-ethernet.wake-on-lan-password:    --

Enable Wake-on-LAN by magic packet on that connection:

# nmcli c modify "wired1" 802-3-ethernet.wake-on-lan magic

Then reboot, possibly two times. To disable Wake-on-Lan, substitute magic with ignore.

The Wake-on-LAN settings can also be changed from the GUI using nm-connection-editor.

Enable WoL in TLP

When using TLP for suspend/hibernate, the WOL_DISABLE setting should be set to N in /etc/default/tlp to allow resuming the computer with WoL.

Trigger a wake up

To trigger WoL on a target machine, its MAC address must be known. To obtain it, execute the following command from the machine:

$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default
   link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: enp1s0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc fq_codel master br0 state UP group default qlen 1000
    link/ether 48:05:ca:09:0e:6a brd ff:ff:ff:ff:ff:ff

Here the MAC address is 48:05:ca:09:0e:6a.

In its simplest form, Wake-on-LAN broadcasts the magic packet containing the MAC address within the current network subnet, below the IP protocol layer. The knowledge of an IP address for the target computer is not necessary.

If used to wake up a computer over the internet or in a different subnet, it typically relies on the router to relay the packet and broadcast it. In this scenario, the external IP address of the router must be known and in some cases the internal IP address of the target machine is needed to ensure the NAT (Network Address Translator) router manages to communicate with the target machine.

Applications that are able to send magic packets for Wake-on-LAN:

  • gWakeOnLAN — GTK+ utility to awake turned off computers through the Wake-on-LAN feature.
https://muflone.com/gwakeonlan/english/ || gwakeonlan
  • wol — Implements Wake-on-LAN functionality in a small program. It wakes up hardware that is Magic Packet compliant.
https://sourceforge.net/projects/wake-on-lan/ || wol

On the same LAN

If you are connected directly to another computer through a network cable, or the traffic within a LAN is not firewalled, then using Wake-on-LAN should be straightforward since there is no need to worry about port redirects.

In the simplest case the default broadcast address 255.255.255.255 is used:

$ wol target_MAC_address

To broadcast the magic packet only to a specific subnet or host, use the -i switch:

$ wol -i target_IP target_MAC_address

Across the internet

When the source and target computers are separated by a NAT router, different solution can be envisaged:

  • If the router supports WoL, one can rely on it to properly broadcast the packet into the local network.

Otherwise Wake-on-Lan can be achieved via port forwarding. The router needs to be configured using one of these two options:

  • Forward a different port to each target machine. This requires any target machine to have a static IP address on its LAN.
  • Forward a single port to the broadcast address. Most routers do not allow to forward to broadcast, however if you can get shell access to your router, through telnet, ssh, serial cable or other mean, run the command:
    $ ip neighbor add 192.168.1.254 lladdr FF:FF:FF:FF:FF:FF dev net0
    This example assumes the network is 192.168.1.0/24 and uses net0 as network interface. Now, forward UDP port 9 to 192.168.1.254. This solution was successfully tested on a Linksys WRT54G running Tomato, and on the Verizon FIOS ActionTec router. For notes on how to do it on a router with DD-WRT firmware, see this tutorial and for a router with OpenWrt firmware, see this tutorial.

In any case, run the following command from the source computer to trigger wake-up:

$ wol -p forwarded_port -i router_IP target_MAC_address

Miscellaneous

Check reception of the magic packets

In order to make sure the WoL packets reach the target computer, one can listen to the UDP port, usually port 9, for magic packets. The magic packet frame expected contains 6 bytes of FF followed by 16 repetitions of the target computer's MAC (6 bytes each) for a total of 102 bytes.

Using netcat

This can be performed by installing gnu-netcat on the target computer and using the following command:

# nc --udp --listen --local-port=9 --hexdump

Then wait for the incoming traffic to appear in the nc terminal.

Using ngrep

Install ngrep on the target computer and type the following command:

# ngrep '\xff{6}(.{6})\1{15}' -x port 9

Example of WoL script

Here is a script that illustrates the use of wol with different machines:

#!/bin/bash

# definition of MAC addresses
monster=01:12:46:82:ab:4f
ghost=01:1a:d2:56:6b:e6

echo "Which PC to wake?"
echo "m) monster"
echo "g) ghost"
echo "q) quit"
read input1
case $input1 in
  m)
    /usr/bin/wol $monster
    ;;
  g)
    # uses wol over the internet provided that port 9 is forwarded to ghost on ghost's router
    /usr/bin/wol --port=9 --host=ghost.mydomain.org $ghost
    ;;
  Q|q)
    break
    ;;
esac

Troubleshooting

Wake-up after shutdown

It is known that some motherboards are affected by a bug that can cause immediate or random wake-up after a shutdown whenever the BIOS WoL feature is enabled (as discussed in this thread for example). The following actions in the BIOS preferences can solve this issue with some motherboards:

  1. Disable all references to xHCI in the USB settings (note this will also disable USB 3.0 at boot time)
  2. Disable EuP 2013 if it is explicitly an option
  3. Optionally enable wake-up on keyboard actions
Note: There are mixed opinions as to the value of #3 above and it may be motherboard dependent.

Battery draining problem

Some laptops have a battery draining problem after shutdown [1]. This might be caused by enabled WOL. To solve this problem, disable it by using ethtool as mentioned above.

# ethtool -s net0 wol d

Realtek

Users with Realtek 8168 8169 8101 8111(C) based NICs (cards / and on-board) may notice a problem where the NIC seems to be disabled on boot and has no Link light. See Network configuration#Realtek no link / WOL problem.

If the link light on the network switch is enabled when the computer is turned off but wake on LAN is still not working, booting the system using the r8168 kernel module at least once and then switching back to the r8169 kernel module included with the kernel seems to fix it at least in the following configurations:

  • MSI B85M-E45 motherboard, BIOS version V10.9, onboard Realtek 8111G chipset

For the r8168 module you might need to set the s5wol=1 module option to enable the wake on LAN functionality.

alx driver support

For some newer Atheros-based NICs (such as Atheros AR8161 and Killer E2500), WOL support has been disabled in the mainline alx module due to a bug causing unintentional wake-up (see this patch discussion). A patch can be applied (or installed as a dkms module) which both restores WOL support and fixes the underlying bug, as outlined in this thread.

See also the pre-patched sources in [2].

See also