Difference between revisions of "Wake-on-LAN"

From ArchWiki
Jump to: navigation, search
m (Ensure that Wake-on-LAN is enabled and survives a reboot)
m (systemd.link: keep it simple)
 
(89 intermediate revisions by 33 users not shown)
Line 1: Line 1:
 
[[Category:Networking]]
 
[[Category:Networking]]
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.  Basically put, Wake-on-LAN, otherwise known as 'wol' is the ability to switch on a computer that is connected to a network (be it the internet or intranet). This can be a very useful ability.
+
[[ja:Wake-on-LAN]]
 +
Wake-on-LAN (WOL) is a feature to switch on a computer via a network connection (be it the internet or intranet).
  
It is important to note that Wake-on-LAN applies to the computers being physically connected (ie, not wireless).
+
== Hardware settings ==
  
==Does my motherboard support Wake-on-LAN?==
+
The target computer's motherboard and [[wikipedia:NIC|NIC]] have to support Wake-on-LAN. Wireless cards do not support Wake-on-LAN, so the target computer has to be physically connected (i.e. by cable) to router or the source computer.
  
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.
+
The Wake-on-LAN feature also has to be enabled in the PC's BIOS. Different motherboard manufactures 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".
  
==Ensure that Wake-on-LAN is enabled and survives a reboot==
+
It is known that some motherboards are affected by a nasty bug that causes reboots rather than shutdowns under certain situations (see [https://bbs.archlinux.org/viewtopic.php?id=173648 this] thread for example). To prevent this bug from surfacing, it is recommended to do the following on the target machine:
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. To manually switch on the Wake-on-LAN feature on your driver, you'll need ethtool:
+
# Disable all references to "xHCI" as it pertains to USB settings.
# pacman -S ethtool
+
# Disable EuP 2013 if it is explicitly an option.
 +
# Optionally enable WOL for keyboard actions.
  
First query the driver to see if it's defaulted to 'on' by using ethtool:
+
{{Note|There are mixed opinions as to the value of #3 above and it may be motherboard dependent.}}
  
<pre> # ethtool eth0 | grep Wake-on
+
== Software configuration ==
        Supports Wake-on: pg
+
Wake-on: d</pre>
+
  
{{Note|We need a 'Wake-on' value of 'g' for WOL to work.}}
+
Depending on the hardware, the network drivers may have WOL switched off by default. To query this status or to change the settings, install {{Pkg|ethtool}}.
  
To enable the wol feature in the driver, simply run the following
+
Query the network device via this command:
# ethtool -s eth0 wol g
+
  
This command does not last beyond the '''next''' reboot. If using netcfg, one can make this setting persistent by adding the following to {{hc|/etc/network.d/PROFILE|2=
+
{{hc|<nowiki># ethtool net0 | grep Wake-on</nowiki>|<nowiki>
POST_UP='/usr/sbin/ethtool -s eth0 wol g'
+
        Supports Wake-on: pumbag
 +
    Wake-on: d
 +
</nowiki>}}
 +
 
 +
The values define what activity to wake on: {{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 of {{ic|g}} is required for WOL to work.
 +
 
 +
To enable the WOL feature in the driver:
 +
 
 +
# ethtool -s net0 wol g
 +
 
 +
This command might not last beyond the next reboot, so it must be repeated via some mechanism. Common solutions are listed in the following subsections.
 +
 
 +
=== Make it persistent ===
 +
 
 +
==== netctl ====
 +
 
 +
If using netctl, one can make this setting persistent by adding the following the netctl profile:
 +
 
 +
{{hc|/etc/netctl/''profile''|2=
 +
ExecUpPost='/usr/bin/ethtool -s net0 wol g'
 +
}}
 +
 
 +
==== systemd.link ====
 +
 
 +
Link-level configuration is possible through systemd. The actual setup is performed by the {{ic|net_setup_link}} udev builtin. Add the {{ic|WakeOnLan}} option to the network link file:
 +
 
 +
{{hc|/etc/systemd/network/50-wired.link|2=
 +
[Link]
 +
WakeOnLan=magic
 +
...
 
}}
 
}}
  
*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
+
{{Note|This configuration applies only to the link-level, and is independent of network-level daemons such as [[NetworkManager]] or [[systemd-networkd]].}}
*For some network cards, you may also need the following command:
+
  
# echo enabled > /sys/class/net/eth0/device/power/wakeup
+
See [[systemd-networkd#link files]] and {{ic|man systemd.link}} for more information.
  
===With systemd===
+
==== systemd service ====
  
Create a new service unit file /etc/systemd/system/wol@.service:
+
This is an equivalent of previous {{ic|systemd.link}} option, but uses a standalone systemd service.
  
{{bc|1=
+
{{hc|/etc/systemd/system/wol@.service|2=
 
[Unit]
 
[Unit]
 
Description=Wake-on-LAN for %i
 
Description=Wake-on-LAN for %i
Line 43: Line 70:
  
 
[Service]
 
[Service]
ExecStart=/usr/sbin/ethtool -s %i wol g
+
ExecStart=/usr/bin/ethtool -s %i wol g
 
Type=oneshot
 
Type=oneshot
  
Line 50: Line 77:
 
}}
 
}}
  
Then activate this new service for your network adapter:
+
Alternatively install the {{AUR|wol-systemd}} package.
  
# systemctl enable wol@eth0
+
Then activate this new service by [[starting]] {{ic|wol@''interface''.service}}.
  
and start it right now
+
==== udev ====
  
# systemctl start wol@eth0
+
[[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*}}:
  
==Wake-on-LAN in different situations==
+
{{hc|/etc/udev/rules.d/99-wol.rules|<nowiki>
 +
ACTION=="add", SUBSYSTEM=="net", NAME=="enp*", RUN+="/usr/bin/ethtool -s $name wol g"
 +
</nowiki>}}
  
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.
+
The {{ic|$name}} placeholder will be replaced by the value of the {{ic|NAME}} variable for the matched device.
  
There are four essential things needed in order to use Wake-on-LAN on a target PC:
+
{{Note|The name of the configuration file is important. Due to the introduction of [[Network configuration#Device_names|persistent device names]] in systemd v197, it is important that the rules matching a specific network interface are named lexicographically after {{ic|80-net-name-slot.rules}}, so that they are applied after the devices gain the persistent names.}}
  
#Some kind of Wake-on-LAN software on the host (your) PC
+
{{Warning|[[udev]] will match the device as soon it becomes available, be this in the [[initramfs]] (before the switch_root) or the main system. The order is not deterministic; there is no guarantee. Be sure that your initramfs includes the necessary udev rules (from {{ic|/etc/udev/rules.d}}) and supporting binaries ({{ic|/usr/bin/ethtool}}).}}
#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.
+
==== cron ====
  
*'''It is recommended that you read the documentation of wol'''
+
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:
  
  man wol
+
  @reboot /usr/bin/ethtool -s [net-device] wol g
wol --help
+
  
*wol requires several parameters, the most basic needed:
+
==== NetworkManager ====
  
wol MACADDRESS
+
In version 1.0.6 NetworkManager [https://www.phoronix.com/scan.php?page=news_item&px=NetworkManager-WoL-Control adds Wake-on-LAN controls]. One way to enable Wake-on-LAN by magic packet is through nmcli.
  
*But it is good practice to include the IP address or hostname, therefore this syntax should be the minimal used:
+
First, search for the name of the wired connection:
  
# wol -i HOSTNAME_OR_IP MACADDRESS
+
{{hc|# nmcli con show|2=
 +
NAME    UUID                                  TYPE            DEVICE
 +
wired1  612e300a-c047-4adb-91e2-12ea7bfe214e  802-3-ethernet  enp0s25
 +
}}
  
*The documentation of wol states that:
+
By following, one can view current status of Wake-on-LAN settings:
  
::''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|# 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:    --
 +
}}
  
*To obtain the MACADDRESS of the target computer:
+
Enable Wake-on-LAN by magic packet on that connection:
  
  $ ip link
+
  # nmcli c modify "wired1" 802-3-ethernet.wake-on-lan magic
  
The port, IP or hostname of the target PC will be addressed in the relevant following sections.
+
Then reboot, possibly two times.
  
===Across your intranet/network (no router)===
+
From version 1.2.0 Wake-on-LAN settings can be changed graphically using {{Pkg|nm-connection-editor}}.
  
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.
+
== Trigger a wake up ==
  
====For two computers connected to each other====
+
To trigger WOL on a target machine, its MAC address and external or internal IP should be known.
  
wol MACADDRESS_OF_TARGET_PC
+
To obtain the internal IP address and MAC address of the target computer, execute the following command:
  
====For computers connected to a non-firewalled router====
+
{{hc|$ ip addr|
 +
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
 +
  inet 127.0.0.1/8 scope host lo
 +
      valid_lft forever preferred_lft forever
 +
  inet6 ::1/128 scope host
 +
      valid_lft forever preferred_lft forever
 +
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
 +
    inet '''192.168.1.20/24''' brd 192.168.1.255 scope global br0
 +
      valid_lft forever preferred_lft forever
 +
    inet6 fe80::6a05:caff:fe09:e6a/64 scope link
 +
      valid_lft forever preferred_lft forever
 +
}}
  
wol -i INTERNAL_IP_OF_TARGET_PC MACADDRESS_OF_TARGET_PC
+
Here the internal IP address is {{ic|192.168.1.20}} and the MAC address is {{ic|48:05:ca:09:0e:6a}}.
  
*To find the internal IP:
+
One program able to send magic packets for WOL is {{Pkg|wol}}.
{{bc|<nowiki>ip addr | grep 'inet '</nowiki>}}
+
  
*Since you are not firewalled, then there is no need to worry about port redirects.
+
=== On the same LAN ===
*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)===
+
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 very easy since there is no need to worry about port redirects.
  
The syntax used in this situation:
+
In the simplest case the default broadcast address {{ic|255.255.255.255}} is used:
  
  wol -p PORT_FORWARDED_TO_INTERNAL_IP -i INTERNAL_IP MACADDRESS_OF_TARGET_PC
+
  $ wol ''target_MAC_address''
  
*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.
+
To broadcast the magic packet only to a specific subnet or host, use the {{ic|-i}} switch:
  
*It is recommended that for multiple computers connected to one computer, to assign a different port forward to each internal IP
+
$ wol -i ''target_IP'' ''target_MAC_address''
  
*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)
+
{{Tip|If you intend to continue using Wake-on-LAN, it is recommended to assign a static IP address to the target computer.}}
  
===Across the internet===
+
=== With port forwarding ===
{{Expansion|Request for OpenWRT instructions.}}
+
The syntax needed in this case:
+
  
wol -p X -i HOSTNAME_OR_EXTERNAL_IP_OF_TARGET MACADDRESS
+
When the source and target computers are separated by a router, Wake-on-LAN can be used via [[wikipedia:Port forwarding|port forwarding]]. The router must be instructed to forward any signal heading for a specific port to the internal IP of the target PC. See for example [[Firewalls]] for configuration details.
  
*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.
+
To trigger the wakeup:
  
 +
$ wol -p ''forwarded_port'' -i ''router_IP'' ''target_MAC_address''
  
Usually it is necessary to forward your wol port (typically UDP 9) to the broadcast address on your network, not to a particular IP. Most routers do not allow you to forward to broadcast, however if you can get shell access to your router (through telnet, ssh, serial cable, etc) you can implement this workaround:
+
In case of multiple computers behind the router, it is recommended to assign a different port forward to each target IP.
ip neighbor add 192.168.1.254 lladdr FF:FF:FF:FF:FF:FF dev eth0
+
  
(The above command assumes your network is 192.168.1.0/24 and use eth0 as network interface). Now, forward UDP port 9 to 192.168.1.254. This has worked for me on a Linksys WRT54G running Tomato, and on the Verizon FIOS ActionTec router.
+
=== Across the internet ===
  
For notes on how to do it on DD-WRT routers, see [http://www.dd-wrt.com/wiki/index.php/WOL#Remote_Wake_On_LAN_via_Port_Forwarding this tutorial].
+
{{Style|Emphasize the difference from [[#With port forwarding]] (if any).}}
  
==Battery draining problem==
+
The syntax needed in this case:
Some laptops have battery draining problem after shutdown [http://ubuntuforums.org/archive/index.php/t-1729782.html]. This might be caused by enabled Wake-on-LAN. To solve this problem, we can disable it by using ethtool as mentioned above.
+
  
  # ethtool -s eth0 wol d
+
  $ wol -p ''target_port'' -i ''target_IP_or_hostname'' ''target_MAC_address''
  
We can also add this to the '''/etc/rc.local''' or '''/etc/rc.local.shutdown'''.
+
*Assuming that you know the external IP of the target machine, and that the [[#With port forwarding|router ports]] on both sides have been forwarding correctly, then this should be exactly as the syntax states.
 +
 
 +
Usually it is necessary to forward your wol port (typically UDP 9) to the broadcast address on your network, not to a particular IP. Most routers do not allow you to forward to broadcast, however if you can get shell access to your router (through telnet, ssh, serial cable, etc) you can implement this workaround:
 +
$ ip neighbor add 192.168.1.254 lladdr FF:FF:FF:FF:FF:FF dev net0
 +
 
 +
(The above command assumes your network is 192.168.1.0/24 and use net0 as network interface). Now, forward UDP port 9 to 192.168.1.254. This has worked for me on a Linksys WRT54G running Tomato, and on the Verizon FIOS ActionTec router.
 +
 
 +
For notes on how to do it on DD-WRT routers, see [http://www.dd-wrt.com/wiki/index.php/WOL#Remote_Wake_On_LAN_via_Port_Forwarding this tutorial].
 +
 
 +
{{Expansion|Request for OpenWRT instructions.}}
  
==Additional Notes==
+
== Miscellaneous ==
  
*A common problem is that some forget to switch on the Wake-on-LAN feature in their BIOS.
+
=== 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.
  
*In some systems the BIOS option "Boot from PCI/PCI-E" needs to be Enabled.
+
# ethtool -s net0 wol d
  
==Example WOL script==
+
=== Example WOL script ===
Here is a script you can use to automate wol to several different machine.  Modify as you see fit:
+
Here is a script to automate WOL to several different machines:
  
<pre>#!/bin/bash
+
{{bc|<nowiki>
 +
#!/bin/bash
  
 
# definition of MAC addresses
 
# definition of MAC addresses
Line 211: Line 261:
  
 
done
 
done
echo  "this is the (quit) end!! c-ya!"</pre>
+
echo  "this is the (quit) end!! c-ya!"
== Resources ==
+
</nowiki>}}
[http://www.depicus.com/wake-on-lan/woli.aspx Wake-On-Lan]
+
 
 +
== Troubleshooting ==
 +
 
 +
=== 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
 +
 
 +
=== Suspend/Resume ===
 +
 
 +
If the computer does not wake after suspend/hibernate when using [[TLP]], set the {{ic|WOL_DISABLE}} value to {{ic|N}} in {{ic|/etc/default/tlp}}.
 +
 
 +
== See also ==
 +
 
 +
* [http://www.depicus.com/wake-on-lan/woli.aspx Wake-On-Lan]

Latest revision as of 09:36, 4 December 2016

Wake-on-LAN (WOL) is a feature to switch on a computer via a network connection (be it the internet or intranet).

Hardware settings

The target computer's motherboard and NIC have to support Wake-on-LAN. Wireless cards do not support Wake-on-LAN, so the target computer has to be physically connected (i.e. by cable) to router or the source computer.

The Wake-on-LAN feature also has to be enabled in the PC's BIOS. Different motherboard manufactures 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 known that some motherboards are affected by a nasty bug that causes reboots rather than shutdowns under certain situations (see this thread for example). To prevent this bug from surfacing, it is recommended to do the following on the target machine:

  1. Disable all references to "xHCI" as it pertains to USB settings.
  2. Disable EuP 2013 if it is explicitly an option.
  3. Optionally enable WOL for keyboard actions.
Note: There are mixed opinions as to the value of #3 above and it may be motherboard dependent.

Software configuration

Depending on the hardware, the network drivers may have WOL switched off by default. To query this status or to change the settings, install ethtool.

Query the network device via this command:

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

The values define what activity to wake on: d (disabled), p (PHY activity), u (unicast activity), m (multicast activity), b (broadcast activity), a (ARP activity), and g (magic packet activity). The value of g is required for WOL to work.

To enable the WOL feature in the driver:

# ethtool -s net0 wol g

This command might not last beyond the next reboot, so it must be repeated via some mechanism. Common solutions are listed in the following subsections.

Make it persistent

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 net0 wol g'

systemd.link

Link-level configuration is possible through systemd. 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
[Link]
WakeOnLan=magic
...
Note: This configuration applies only to the link-level, and is independent of network-level daemons such as NetworkManager or systemd-networkd.

See systemd-networkd#link files and man systemd.link for more information.

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*:

/etc/udev/rules.d/99-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.

Note: The name of the configuration file is important. Due to the introduction of persistent device names in systemd v197, it is important that the rules matching a specific network interface are named lexicographically after 80-net-name-slot.rules, so that they are applied after the devices gain the persistent names.
Warning: udev will match the device as soon it becomes available, be this in the initramfs (before the switch_root) or the main system. The order is not deterministic; there is no guarantee. Be sure that your initramfs includes the necessary udev rules (from /etc/udev/rules.d) and supporting binaries (/usr/bin/ethtool).

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 [net-device] wol g

NetworkManager

In version 1.0.6 NetworkManager adds Wake-on-LAN controls. 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.

From version 1.2.0 Wake-on-LAN settings can be changed graphically using nm-connection-editor.

Trigger a wake up

To trigger WOL on a target machine, its MAC address and external or internal IP should be known.

To obtain the internal IP address and MAC address of the target computer, execute the following command:

$ ip addr
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
   inet 127.0.0.1/8 scope host lo
      valid_lft forever preferred_lft forever
   inet6 ::1/128 scope host
      valid_lft forever preferred_lft forever
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
    inet 192.168.1.20/24 brd 192.168.1.255 scope global br0
       valid_lft forever preferred_lft forever
    inet6 fe80::6a05:caff:fe09:e6a/64 scope link
       valid_lft forever preferred_lft forever

Here the internal IP address is 192.168.1.20 and the MAC address is 48:05:ca:09:0e:6a.

One program able to send magic packets for WOL is 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 very easy 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
Tip: If you intend to continue using Wake-on-LAN, it is recommended to assign a static IP address to the target computer.

With port forwarding

When the source and target computers are separated by a router, Wake-on-LAN can be used via port forwarding. The router must be instructed to forward any signal heading for a specific port to the internal IP of the target PC. See for example Firewalls for configuration details.

To trigger the wakeup:

$ wol -p forwarded_port -i router_IP target_MAC_address

In case of multiple computers behind the router, it is recommended to assign a different port forward to each target IP.

Across the internet

Tango-edit-clear.pngThis article or section needs language, wiki syntax or style improvements.Tango-edit-clear.png

Reason: Emphasize the difference from #With port forwarding (if any). (Discuss in Talk:Wake-on-LAN#)

The syntax needed in this case:

$ wol -p target_port -i target_IP_or_hostname target_MAC_address
  • Assuming that you know the external IP of the target machine, and that the router ports on both sides have been forwarding correctly, then this should be exactly as the syntax states.

Usually it is necessary to forward your wol port (typically UDP 9) to the broadcast address on your network, not to a particular IP. Most routers do not allow you to forward to broadcast, however if you can get shell access to your router (through telnet, ssh, serial cable, etc) you can implement this workaround:

$ ip neighbor add 192.168.1.254 lladdr FF:FF:FF:FF:FF:FF dev net0

(The above command assumes your network is 192.168.1.0/24 and use net0 as network interface). Now, forward UDP port 9 to 192.168.1.254. This has worked for me on a Linksys WRT54G running Tomato, and on the Verizon FIOS ActionTec router.

For notes on how to do it on DD-WRT routers, see this tutorial.

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: Request for OpenWRT instructions. (Discuss in Talk:Wake-on-LAN#)

Miscellaneous

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

Example WOL script

Here is a script to automate WOL to several different machines:

#!/bin/bash

# definition of MAC addresses
monster=01:12:46:82:ab:4f
chronic=00:3a:53:21:bc:30
powerless=1a:32:41:02:29:92
ghost=01:1a:d2:56:6b:e6

while [ "$input1" != quit ]; do
echo "Which PC to wake?"
echo "p) powerless"
echo "m) monster"
echo "c) chronic"
echo "g) ghost"
echo "b) wake monster, wait 40sec, then wake chronic"
echo "q) quit and take no action"
read input1
  if [ $input1 == p ]; then
  /usr/bin/wol $powerless
  exit 1
fi

if [ $input1 == m ]; then
  /usr/bin/wol $monster
  exit 1
fi

if [ $input1 == c ]; then
  /usr/bin/wol $chronic
  exit 1
fi

# this line requires an IP address in /etc/hosts for ghost
# and should use wol over the internet provided that port 9
# is forwarded to ghost on ghost's router

if [ $input1 == g ]; then
  /usr/bin/wol -v -h -p 9 ghost $ghost
  exit 1
fi

if [ $input1 == b ]; then
  /usr/bin/wol $monster
  echo "monster sent, now waiting for 40sec then waking chronic"
  sleep 40
  /usr/bin/wol $chronic
  exit 1
fi

if [ $input1 == Q ] || [ $input1 == q ]; then
echo "later!"
exit 1
fi

done
echo  "this is the (quit) end!! c-ya!"

Troubleshooting

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

Suspend/Resume

If the computer does not wake after suspend/hibernate when using TLP, set the WOL_DISABLE value to N in /etc/default/tlp.

See also