What's new

WOL script: Wake Up your NAS / PC when a VPN client connects

  • SNBForums Code of Conduct

    SNBForums is a community for everyone, no matter what their level of experience.

    Please be tolerant and patient of others, especially newcomers. We are all here to share and learn!

    The rules are simple: Be patient, be nice, be helpful or be gone!

Gingko

New Around Here
This tutorial is intended for people who want to wake up some device (a NAS, PC, ...) when a VPN client connects to the VPN server on your Asus Router.

It is similar to WOL Script Wake Up Your Webserver On Internet Traffic except that the trigger comes from the VPN connection.

To setup follow these steps:
  1. Install Asuswrt-Merlin firmware.
  2. Setup a VPN server on your Asus Router and a VPN client e.g. on your mobile phone (or any other client device).
  3. On the Asus Router admin page:
    Administration > Enable JFFS custom scripts and configs: Yes
    Administration > Enable SSH: Yes
  4. Setup WinSCP and open a session to your router
  5. Create the script file /jffs/scripts/ovpn-client-connect.sh
  6. Edit the ovpn-client-connect.sh script with the following content:
    #!/bin/sh
    logger "VPN client connected!"
    # MAC address of the device you want to wake up
    /usr/sbin/ether-wake -i br0 -b "00:11:22:33:44:55"
    exit 0
  7. While saving the script, make sure line endings are Unix style (LF) but not Windows style (CR LF)
  8. Make the script executable (either in WinSCP edit file properties: RWX or using PuTTY: chmod a+x /jffs/scripts/ovpn-client-connect.sh)
  9. Go back to your Asus Router admin page:
    VPN > VPN Server > VPN Details: Advanced Settings
    VPN > VPN Server > Custom Configuration, enter the lines:
    script-security 2
    client-connect /jffs/scripts/ovpn-client-connect.sh
  10. Apply and test it
An analogous hook exists when a client disconnects, you may invoke a similar script:
client-disconnect /jffs/scripts/ovpn-client-disconnect.sh

Notes
  • Commands added to the "Custom Configuration" section will be embedded in the OpenVPN configuration file /etc/openvpn/server1/config.ovpn
  • It takes about one or two minutes after a client has disconnected until the client-disconnect script gets executed.
  • Note that the openvpn-event script (described here) seems not appropriate for this purpose since it is invoked only at VPN server startup and shutdown, but not when a client connects or disconnects. The openvpn-event script is linked to the OpenVPN commands up and down.
  • It's suggested to keep a backup of scripts located in the JFFS partition, since the partition may be erased during firmware upgrade (as stated here)
 
Last edited:

Similar threads

Latest threads

Sign Up For SNBForums Daily Digest

Get an update of what's new every day delivered to your mailbox. Sign up here!
Top