Monthly Archives: March 2010

Wake on LAN through router

Okay, here is the task. There is a router that performs NAT, and there is a host behind it. You want to power on the host using Wake-on-LAN from somewhere in the Internet.

The nature of the WOL is such that it requires level 2 (Ethernet) access to the network, which is obviously impossible from the Internet or anywhere else outside of the LAN segment. In order to circumvent this, some higher-level protocol is used. UDP port 9 is the usual choice because it is usually ignored by any reasonable software. So it works like this: you send a UDP datagram to the target host, it detects a special sequence inside the datagram and powers on. The nature of the sequence used in the WOL is such that you need to know the MAC address of the target host in order to create the datagram, this is to avoid as much accidental power-ons as possible.

Easy? Unfortunately, not that easy. In order to send a UDP datagram, you need to know the destination IP address. But since the host is turned off, it doesn’t have an IP address, only the MAC one. What to do? And if the host in question is behind a router, the MAC doesn’t help as you can’t use it.

There are three two possible ways to deal with this. No matter what you do, you obviously must use the router’s external IP address to send the UDP datagram. Then it is all about how to force the router to relay it to the target host.

One way is to use DMZ. No, that won’t work. Even if you specify your host as DMZ in the router settings, it won’t solve the problem of figuring out the MAC from an IP address.

Another way is to use static ARP. ARP is the protocol used to determine MACs from IPs. If your host is powered off, then ARP asks every host in the LAN about that IP, and since no-one has it, it fails to determine its MAC. If you can somehow assign static MAC to a specific IP, it would allow the router to use port forwarding to forward something to the host even if it’s powered off. One disadvantage of this approach is that you need to manage your ARP table by hand, altering it each time the MAC address of the target host changes. Not a big deal for most home networks. Another disadvantage is that accessing ARP tables and making static entries can be tricky or even impossible, depending on the router used. That’s too bad. But if it works, then it looks like this:

Internet -> WAN interface: a UDP datagram arrives.
router: What the hell is this? Does it belong to any known session? No. Is there any port forwarding rule for it? Yes. What is the LAN address for it? Oh, here it is. What is its MAC? Okay, it’s in the ARP table, let’s forward it.
LAN interface -> target host: a UDP datagram is forwarded.
target host: Wake up.

And the last way I can think of is to use broadcast. It is the most reasonable and the easiest to set up. You set up your router to forward UDP port 9 to LAN broadcast address, so that every host in the LAN receives it, no ARP involved. The obvious advantage is that it should always work and requires no special set-up that involves MACs. Only one forwarding rule is needed, and it could work for many hosts too. The bad news are that it doesn’t work on some routers for some unclear and possibly stupid reasons. They just don’t seem to be able to forward to the broadcast address. But anyway, it should work as follows:

Internet -> WAN interface: a UDP datagram arrives.
router: What the hell is this? Does it belong to any known session? No. Is there any port forwarding rule for it? Yes. What is the LAN address for it? Oh, it’s the broadcast. No ARP needed then. Hey, everybody, get this!
LAN interface -> the broadcast IP: a UDP datagram is forwarded.
target host: Got something from broadcast. Hey, it’s my MAC! Wake up.

That being said, I still can’t figure out a way to configure D-Link DSL-2540U to forward to the broadcast address. Fuck D-Link. There seems to be no obvious way to configure static ARP entries too.

OS upgrade

Upgrade Ubuntu 9.04 to 9.10. Run Update Manager, click upgrade, wait until done. Success. All free.

Upgrade Vista Basic to Windows 7. Go to Microsoft Website, find out that it is only possible to upgrade Vista Home Premium. Try to find out about upgrading Basic to Home Premium. Read a lot of useless stuff, find out about Anytime Upgrade that costs $80. Read more useless stuff, eventually find out that it requires physical media and is only available to Canada and the US. Failure.

Fuck you, Microsoft. Not only upgrading Vista to Vista costs you money, but it is also impossible unless one wishes to do a clean install, which is a pain in the arse.