While Remote Desktop will already work on a running PC - what if it’s sleeping?
We need to wake it up!
On the server side, “waking on LAN” is more about the hardware.
It must be enabled in the BIOS first, and then the OS just needs to enable/allow it.
For some reason it’s not a toggle - you have to install & run a script.
First, install new package:
sudo apt install ethtool -y
Then, get the “name” of the network device.
Using this command, the name will be similar to enp5s0 for a ethernet connection.
ip a
Run this command, replacing enp5s0 with your network device:
Look for Wake-on “d” = disable, or “g” = enable.
sudo ethtool enp5s0
The above step likely showed a ‘d’ for disabled.
We need to flip to ‘g’ every boot.
sudo --preserve-env systemctl edit --force --full wol-enable.service
[Unit]
Description=Enable Wake-up on LAN
[Service]
Type=oneshot
ExecStart=/sbin/ethtool -s enp5s0 wol g
[Install]
WantedBy=basic.target
sudo systemctl daemon-reload && sudo systemctl enable wol-enable.service
sudo ethtool enp5s0
On client side, a new package will send the wake signal.
We’ll incorporate it into the Remote Desktop initiation for some automation.
Install the app
sudo apt install wakeonlan
Then we need to make the new script, that Remmina (already installed) will run.
sudo nano /usr/local/bin/wgrog
#!/bin/bash
count=0;
while true; do
count=$count+1
PING=$(ping 192.168.88.169 -W1 -c1)
if [[ $PING == *"1 received"* ]]; then
exit 0
fi
if (( count > 25 )); then
exit 1
fi
/usr/bin/wakeonlan -i 192.168.88.255 9C:6B:00:18:B2:ED
sleep 1
done
New script needs to be executable as a program:
sudo chmod +x /usr/local/bin/wgrog
Final step - back in Remmina, settings, enter this in “preload behavior”
Calling the new script will WAKE the server, before trying to Remote Desktop into it.
bash /usr/local/bin/wgrog
I had a couple weird issues with scripts not running, when nothing looked wrong.
It must have been hidden formatting, and this fixed it.
sudo apt install shellcheck
tr -d '\r' scriptname newgoodscriptname