HowTo: RPi as WakeOnLAN server

Step-by-Step descriptions of how to do things.
Post Reply
User avatar
peter_b
Chatterbox
Posts: 383
Joined: Tue Nov 12, 2013 2:05 am

HowTo: RPi as WakeOnLAN server

Post 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! :)
Post Reply