07 Wake on LAN

Table of Contents

Previous Page

Next Page


While Remote Desktop will already work on a running PC - what if it’s sleeping?
We need to wake it up!

SERVER SIDE - Wake On Lan (any Distro)

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.

  1. This next command will open an empty script for us to write:
sudo --preserve-env systemctl edit --force --full wol-enable.service
  1. Copy this into the document.
    After, hit “ctrl-x” to close, and hit “y” to save before closing.
    Remember again to change ethernet address to yours
[Unit]
Description=Enable Wake-up on LAN

[Service]
Type=oneshot
ExecStart=/sbin/ethtool -s enp5s0 wol g

[Install]
WantedBy=basic.target
  1. Then, reload & enable the new service, that will run on boot!
sudo systemctl daemon-reload && sudo systemctl enable wol-enable.service
  1. For fun, re-run this, AFTER a reboot, to make sure Wake = ‘g’:
sudo ethtool enp5s0

CLIENT SIDE - Sending a Wake Magicpacket

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.

  1. Open new empty script
sudo nano /usr/local/bin/wgrog
  1. Copy this into the document.
    You will need to get the local IP and the MAC address for the server!
    After, hit “ctrl-x” to close, and hit “y” to save before closing.
#!/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

Random tools for scripts

I had a couple weird issues with scripts not running, when nothing looked wrong.
It must have been hidden formatting, and this fixed it.

  1. Install shellcheck
sudo apt install shellcheck
  1. run “shellcheck scriptname” to see report on issues
  2. Then running this may correct/translate the script:
tr -d '\r' scriptname newgoodscriptname

Table of Contents

Previous Page

Next Page