Thursday, February 3, 2011

How to get Wake-on-LAN working?

I have a PC behind a router with a dynamic IP address that I want to configure for wake-on-LAN.

How do I send the magic packet to the PC? Do I configure my router to forward UDP port 6 to the PC? How would I send the packet from another PC on the network? How about a PC outside the network?

Is this even possible?

Update: here is a pertinent configuration screen from my router. Any hope?

  • It sounds like some reading-up on WOL is probably in order first. Some additional reading about Ethernet, ARP, and UDP/IP is probably in order, too.

    The WOL behavior in a client is triggered by a "magic packet". The magic packet can be encapsulated in any type of transport (UDP over IP, IPX, etc). The magic packet byte sequence just needs to be in the payload of a packet that the NIC to be woken-up will receive.

    Sending WOL requests on the LAN is easy. Get a utility to make magic packets (like mc-wol for Windows) and fire away.

    Sending WOL requests from the Internet is more problematic. You're on the right track w/ port-forwarding a UDP port from the Internet to the LAN, but there are other concerns.

    You have a problem with unicast WOL requests from the Internet as follows: The MAC address of your WOL client computer won't be in the router's ARP table because, as the WOL client is powered-off, such an ARP entry would have aged out. When your router receives an IP packet port-forwarded to the WOL client's IP address while the WOL client is powered-off and its MAC address is aged out of the ARP table the router will not be able to deliver the packet to the client. You will need a router with static ARP capability to make this work.

    The broadcast route is even less likely. Since you likely don't have a public subnet behind your router, but rather are using NAT to share a single public IP address on your LAN, there's no way to remotely address a packet to the subnet-broadcast address of your LAN subnet such that the router (if it could forward directed broadcasts) would generate a layer 2 broadcast with the WOL packet to allow the WOL client to "see" it.

    WOL on your LAN will be easy. WOL across the Internet isn't so simple.

    George Edison : My router can assign static IP addresses based on MAC addresses. Does that help?
    George Edison : Also, you mention that any protocol will work... will any port work? Is there a preferred port?
    Evan Anderson : @George Edison: You need static ARP entries. Assigning IP addresses based on MAC addresses (typically referred to as DHCP reservations) has nothing to do with ARP. You can use any UDP port you want. The Wikipedia article mentions some possible "preferred" ports, but I'm not aware of an IANA-registered port.
    George Edison : @Evan: I updated the question with a screenshot from the router config. It mentions "If adding a PC which is not connected and ON, you must provide the MAC (hardware) address." Won't this give the router the IP-to-MAC correspondence it needs to wake the PC?
    Evan Anderson : I stand corrected. I've never seen that particular router before, but it certainly looks like they've got a static ARP configuration there. Looks like you're in business.
  • Rather than repeat why you are going to have problems I'll simply describe how I overcame those problems Evan has already explained.

    My firewall/router is Linux based, which means I'm able to run commands on it. To wake up machines on the LAN I first SSH into the firewall and then run a Perl script which creates the magic packet and sends it out to the LAN. The MAC address of the target can be either passed as a command line parameter or hard coded, as appropriate.

    Of course if you are unable to execute commands on your router you will need to find an alternative means.

    Evan Anderson : It's a bit of a catch 22 if the router won't support arbitrary command functonality. I'd say "leave a PC turned on behind the router that you can access remotely and send the magic packet from" but, then, that kinda defeats the purpose re: trying to save power by turning things off.
    George Edison : Unfortunately this is not possible, as the only other PC connected to the network is usually off.
  • As Evan and John already covered, WoL over the internet is unlikely to work.

    You need some sort of device inside of the firewall that can send the packets on your behalf. We use a web application hosted on our intranet. Sounds like that's not an option, so there's really only three other options that come to mind:

    • Leave a low-powered device, like a Linux-based thin client from ebay powered up for your PC wakeup needs.
    • If you happen to have an Intel-platform PC with vPro, buy a certificate and you'll be able to wake up PC via the service processor instead of WoL.
    • I haven't done this myself, but I believe that some UPS (Uninterruptible Power Supply) units provide the ability to power on and off ports. Not sure what a unit that is capable of doing that costs, but it is probably worth looking into.

0 comments:

Post a Comment