In order to be able to Wake On LAN (WOL) a computer, a NAS (Network Attached Storage) etc. from the Internet (WAN), perform the following configuration steps.
Altough the examples in this article use the ASUS Router RT-AC88U, the configuration in general is not specific to this router. The only specific part is how to make the static ARP rule "survive" a router reboot.
DDNS
Configure a (DDNS) Dynamic Domain Name System in order to address your home network, even with changing ip addresses.
This is not described here. There are plenty of descriptions around. (The ASUS router can configure one for you automatically):
Our exemplary DDNS here is: myDDNS.asuscomm.com
In order to improve security a little (really only "a little"), do not use standard ports for WOL.
For example, we will use the port: 4231
NAS
For example in the NAS configure the Port: 22 for WOL.
ASUS Router
Port Forwarding
On the router configure the mapping of the incoming Port 4321 to the NAS Port 22 and a broadcast LAN ip address 192.168.1.254.
ARP
Setup a ARP (Address Resolution Protocol) entry / rule, that redirects the WOL packets send to destination 192.168.1.254 to be broadcast to all MAC addresses (i.e. to ff:ff:ff:ff:ff:ff)
Login to the router via telnet or ssh as admin (root) user.
Once logged in, use this command in order to add the needed ARP entry:
arp -s 192.168.1.254 ff:ff:ff:ff:ff:ff
On another router (a Netgear router with Gargoyle, a Firmware based on OpenWrt), I used the following statement in order to add this entry:
ip neigh add 192.168.1.254 lladdr ff:ff:ff:ff:ff:ff nud permanent dev br-lan
List the resulting ARP table containing the new highlighted entry:
admin@(none):/jffs/scripts# arp
? (192.168.1.155) at <incomplete> on br0
? (XXX.XXX.178.1) at XX:XX:XX:XX:fc:81 [ether] on eth0
? (192.168.1.254) at ff:ff:ff:ff:ff:ff [ether] PERM on br0
? (192.168.1.58) at XX:XX:XX:XX:4c:c4 [ether] on br0
? (192.168.1.251) at XX:XX:XX:XX:5d:0a [ether] on br0
? (192.168.1.170) at XX:XX:XX:XX:0e:f3 [ether] on br0
? (192.168.1.40) at XX:XX:XX:XX:8a:58 [ether] on br0
Now you can check, if this configuration works with Programs / Apps that can send WOL Packets.
As target you will need to set your chosen DDNS and port. (In our example it would be myDDNS.asuscomm.com and port 4231)
On the iPhone I use the "iNet WOL" app.
Although this ARP entry is marked as permanent (PERM), the configuration will disappear once the router is rebooted.
In order to avoid this, set up a script that executes the ARP statement from above when the router reboots.
This can be achieved by using the ASUSWRT feature that executes a user defined script, every time a USB drive is mounted.
The ASUS router offers a small non volatile "disk storage" under /jffs
So, create a folder in this directory. In this example, the folder "scripts".
This generates the script wan-wol.sh in the current folder:
cat <<EOF > wan-wol.sh
#!/bin/sh
scriptName="/jffs/scripts/\$(basename $0)"
myIp="192.168.1.254"
/usr/bin/logger -t "\${scriptName}" \$$ "arp -s \${myIp} ff:ff:ff:ff:ff:ff"
arp -s \$myIp ff:ff:ff:ff:ff:ff
/usr/bin/logger -t "\${scriptName}" \$$ "Check: \$(arp | grep $myIp)"
EOF
Displaying the content of this script:
OS> cat /jffs/scripts/wan-wol.sh
The resulting script should look like:
#!/bin/sh
scriptName="/jffs/scripts/$(basename $0)"
myIp="192.168.1.254"
/usr/bin/logger -t "${scriptName}" $$ "arp -s $myIp ff:ff:ff:ff:ff:ff"
arp -s $myIp ff:ff:ff:ff:ff:ff
/usr/bin/logger -t "${scriptName}" $$ "Check: $(arp | grep $myIp)"
Only the highlighted lines are really relevant.
The rest in only for logging.
Do not forget to make the script executable:
admin@(none):/jffs/scripts# chmod a+x wan-wol.sh
Make a copy of this script elsewhere, because it can be deleted, if a new firmware version is installed.
NVRAM
With nvram, the parameters of the router can be shown/configured.
Display the actual value of the parameter "script_usbmount" in case you need to set it back.
In the example below, it was not set:
master@(none):/tmp/home/root# nvram show 2>&1 | grep script_usbmount
script_usbmount=
Set the parameter "script_usbmount" in order for your script to be executed when a USB drive is mounted:
master@(none):/jffs/scripts# nvram set script_usbmount="/jffs/scripts/wan-wol.sh"
master@(none):/jffs/scripts# nvram commit
Check the result:
master@(none):/jffs/scripts# nvram show 2>&1 | grep script_usbmount
script_usbmount=/jffs/scripts/wan-wol.sh
After the router is rebooted, the following highlighted lines should appear in the router log (if you implement the logging lines in the script from above):
Tags: Asus, Router, NAS, WOL, ARP, Publish, RT-AC88U
July 29, 2016 at 10:39PM