Okay, after some days of struggle and figuring this stuff out, I've finally made it happen. What I did was:
- wrote a bash script that sends a magic packet with the mac address of the target pc to the local IP-address with a port of that pc.
#!/bin/bash
sudo wakeonlan -i 12.121.12.12 -p 99 1a:2b:3c:4d:5e:6f
- installed socat
- figured out the command which I need to make it listen constantly for the packet on the specified port:
sudo socat -u udp-recvfrom:10,fork exec:scripts/pi-wol.sh
- added it as a systemd service by using this guide. Had to move the script to /usr/bin, so it could be started at startup by root. Eventually the service file looked like this:
[Unit]
Description=Socat WOL
[Service]
Type=simple
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=socat-wol
ExecStart=/usr/bin/socat -u udp-recvfrom:10,fork exec:/usr/bin/pi-wol.sh
[Install]
WantedBy=multi-user.target
What happens now is when I send a magic packet to my RPi through internet (don't forget to port forward sent packets to your local Pi) RPi recieves it and the script is triggered - it sends a wol-packet to my target pc waking it up from turned off state.
I spent 4 days of constant googling and getting on people's nerves to get here and now I see it all could be done in 4 simple steps which take 15 minutes or less.