Saturday, November 26, 2011

Setting up wake-on LAN in your own home

One of the drawbacks of using Slicehost or Amazon EC2 is that you're pretty much paying $16-$20/month for a VPS server even when you're not accessing the server that much. If you have data that you also don't want being stored on a cloud, you may opt to setup your own home server to store this information. You may want to have the ability to access this data but not have your machine turned on all the time adding to your electricity bill.

First, your computer(s) needs to have wake-on-LAN enabled in the BIOS and your computer's Ethernet port must be plugged directly into a switch/router (wireless wake-on LAN NIC cards may also be possible). For Toshiba laptops, for instance, you need to reboot, hit Esc and then F1 to enter the BIOS. You can then enable Wake-on-LAN support and save the changes.

You also need a router that can run the DD-WRT or Tomoto open source firmware. If you use the VPN version of the DD-WRT, you can also setup a PPTP server with DynDNS so that you can VPN into your server even though you're using an ISP that does not provides static IP's. You'll want to setup your DD-WRT server to assign a static IP address to your remote computer (inside the Services tab, look for static leases).

If have one of the Windows Professional versions, you can also take advantage of the Remote Desktop servers. You can enable Remote Desktop Sever by going to the Control Panel > System > Remote. You can also right-click My Computer (if the icon is shown on the desktop) and choose Properties.

To verify that Wake-on-LAN works, you can use Netcat/socat to test things out. This blog posting explains how the magic packet for Wake-on-LAN is constructed: 6 bytes of FF followed by the LAN MAC address repeated 16 times. The bash script used to generate a hex version is listed as follows -- you just need to substitute the ETHER parameter with the MAC address of the machine that will need to be woken up:
ETHER="aa:bb:cc:dd:ee:ff"
ETHER2=`echo $ETHER | sed "s/://g"`
ETHER3="${ETHER2}${ETHER2}${ETHER2}${ETHER2}"
ETHER4="FFFFFFFFFFFF${ETHER3}${ETHER3}${ETHER3}${ETHER3}"
echo ${ETHER4} | xxd -r -p > wake.packet

The blog posting points out that you can use netcat to send to a router IP, but what about sending a broadcast address from within the same network? For this purpose, the socat utility seems to work better (not sure if netcat allows sending to broadcast IP addresses?)
socat - UDP-DATAGRAM:192.168.0.255:7,broadcast < wake.packet 

You can also use DD-WRT to wake up any device (check the WoL section) too, but the above information is more background information for how it actualy works!

To setup dynamic DNS, you'll need to go to the DDNS page of the DD-WRT firmware and input your username/pw. The DynDNS service is now $20/year, though it used to be free in recent years. The instructions for setting DynDNS are posted at: http://www.dd-wrt.com/wiki/index.php/DDNS_-_How_to_setup_Custom_DDNS_settings_using_embedded_inadyn_-_HOWTO

To setup the PPTP server for VPN, go to the PPTP section and follow the instructions according to http://www.dd-wrt.com/wiki/index.php/PPTP_Server_Configuration. One thing to note is that the PPTP server IP should be different from your router's internal IP, and the CHAP secrets format is ( * *). Yes, there is an asterisk after username and password.

Ubuntu comes with 'tsclient', which is a Remote Desktop Connection. Once you've setup a VPN connection correctly, you can To get your Windows machine to hibernate, you can also create this batch file and add to your Desktop:

%windir%\system32\rundll32.exe powrprof.dll,SetSuspendState Hibernate


You can also get an iPad/Android app to wake up your computer remotely -- we found Mocha WoL, a free app that lets you wake up the machine remotely. You can also set the hostname to a DynDNS machine, and assuming you have UDP port forwarding setup to relay WoL broadcasts, it should be able to wake up the machine remotely.

No comments:

Post a Comment