Wake-on-LAN - ArchWiki

# 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).

## 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 implicitly 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 does not last beyond the next reboot, so it must be repeated via some mechanism. Common solutions are listed in the following subsections.

### With 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'

### With systemd

If systemd-networkd is used to setup machine's network then it is easy to enable Wake-On-Lan using `systemd.link` configuration. Add `WakeOnLan` option to the network link file:

    /etc/systemd/network/wired.link

    [Link]
    WakeOnLan=magic

See `man systemd.link` for more information.

### With standalone 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`.

### With udev

udev is capable of running any command as soon as a device is visible. Here, udev will turn on WOL. Put the following in /etc/udev/rules.d/50-wol.rules, replacing N with the number for the target interface:

    ACTION=="add", SUBSYSTEM=="net", KERNEL=="netN", RUN+="/usr/bin/ethtool -s %k wol g"

This tells udev to run "/usr/bin/ethtool -s netN wol g" as soon as the device netN exists. To turn on wake on lan for all new devices, replace the N with a '*':

    ACTION=="add", SUBSYSTEM=="net", KERNEL=="net*", RUN+="/usr/bin/ethtool -s %k wol g"

### With 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

## 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

This article or section needs language, wiki syntax or style improvements.

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.

This article or section needs expansion.

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

## See also

- Wake-On-Lan

Category:

- Networking