01 May 2014

I have a linux box behind a router in my flat. Usually, it is powered off when I am in office. Now and then, however, I would like to power it on and download/upload some materials from/to it. This can be achieved by WOL (and DDNS if you don't have a fixed IP).

Wake on Lan

  1. On host, ensure BIOS enabled Wake On Lan (WOL).

    Take Dell Optplex 360 as an example, set it in: BIOS -> Power Management -> Remote Wakeup.

  2. On host, ensure NIC enabled WOL.
    • To check
      $ sudo ethtool eth0 | grep Wake
              Supports Wake-on: g
              Wake-on: g
    • To enable
      sudo ethtool -s eth0 wol g

      Where "wol g" -> Wake on MagicPacket.

      If your NIC card supports SecureOn password for MagicPacket ("Supports Wake-on:" includes "s"), you can set a password for wol:

      sudo ethtool -s eth0 wol s sopass 11:22:33:aa:bb:cc
  3. On client, run wol or whatever tool to send wake-up packets. E.g.
    wol 00:23:ae:98:83:91
    wol --passwd=11-22-33-aa-bb-cc 00:23:ae:98:83:91

NOTE: Eventhough WOL itself is independent of operating systems, it may be still inmpacted by OS since OS may put NIC into incorrect state.

  1. Some operating systems will turn off WOL after reboot.
  2. Some operating systems do not "gracefully" shutdown NIC. (In this case, try unplugging power cord to reset the NIC.)

Wake on Wan

This is basically the same as WOL except that WOL magic packets have to traverse the WAN, which is solved by DDNS.

  1. On host, ensure wake-on-lan configured and works.
  2. On router, setup up DDNS if the router has no static public IP.
  3. On router, statically allocate an IP to the designated host.
  4. On router, create a static ARP entry to the host.

    This way, even the host isn't on, router still able to send forward packets to it.

  5. On router, create a port forwarding rule (虚拟服务器映射) to map UDP port 9 to the host.

    The default UDP port number for WOL is 9, but it doesn't matter at all to NIC. That is so long as the packet arrives at the NIC, the NIC will boot the host.

    Therefore, the port number needn't be 9. You can reuse any another already mapped UDP port so long as it can get WOL magic packets to the host.

  6. To wake the host
    • On a command line
      # Linux version of "wol", explicitly specify the port as wol send to UDP port
      # 40000 by default
      wol 00:23:ae:98:83:91 -i your.domain.name -p 9
      # for OS-X, the equivalent command is
      wakeonlan -i your.domain.name 00:23:ae:98:83:91
    • Or use web: http://wakeonlan.me, note that this web send packets to UDP port 9 by default.

blog comments powered by Disqus