Page 1 of 1

HowTo: RPi as WakeOnLAN server

Posted: Fri Apr 12, 2019 7:48 am
by peter_b
This is actually based on the steps described on instructables.com:
Raspberry Pi As Wake on LAN Server.

1) Install "etherwake" package:

Code: Select all

$ apt install etherwake
In my network, I've got all ethernet MAC IDs configured in my ISC DHCP configuration (Raspbian/Debian), so I'm using that "dhcpd.conf" config file as a lookup table when I want to WOL a machine by its hostname.

Here's the quick-n-dirty BASH hack:

Code: Select all

#!/bin/bash

TARGET="$1"
DHCP_CONF="/etc/dhcp/dhcpd.conf"

# Grep the MAC address from the DHCP config file:
CMD="grep -A 2 -i 'host $TARGET' $DHCP_CONF | grep 'hardware ethernet' | cut -d ' ' -f 5"
MAC_ID=$(eval "$CMD")
# MAC IDs are 17 digits long. Cut it:
MAC_ID=${MAC_ID:0:17}

echo "$TARGET=$MAC_ID"
etherwake $MAC_ID
You can call that like this:
"./wol.sh HOSTNAME"

It will then search the hostname in dhcpd.conf, grep its ethernet line and cut that to the address string.
When it has that, it calls `etherwake`. The target HOSTNAME should now wake up :D

Thanks Quintaar! :)