Setting Up Wake On LAN in Ubuntu

ubuntu server homelab

Wake On LAN (WOL) allows you to turn on the computer from another device in the same network.

Determining Network Interface Card (NIC) name

sudo lshw -c network

Under the Ethernet Interface copy the logical name.

Enabling WOL in the BIOS

Using Integrated NIC

In the BIOS enable "Wake up on PCI event", "Wake up on LAN" or similar option.

Using Non-Integrated NIC

In the BIOS enable the option to allow USB and/or PCI devices to wake-up the computer.

Determining WOL support in NIC

sudo ethtool <name>

where <name> is the logical name you copied.

The output would contain a line similar to Supports Wake-on: <letters> where <letters> contains the letter g, the NIC should support the WOL Magic Packet.

Enabling WOL in the NIC

The above output would also contain a line similar to Wake-on: <letters> and if <letters> contains g and not d, then Magic Packet is enabled. However, if does contain d, WoL needs to be enabled by running

sudo ethtool -s <name> wol g

Enabling WOL on every boot

Find the path to ethtool running the following and copy the output.

sudo which ethtool

Create a file named wol.service at /etc/systemd/system/.

sudo nano /etc/systemd/system/wol.service

Paste the following

Description=Enable Wake On Lan

ExecStart=/usr/sbin/ethtool -s <name> wol g


Ctrl+S to save and Ctrl+X to exit.

Restart and enable the service.

sudo systemctl daemon-reload
sudo systemctl enable wol.service

Check whether the service is running.

systemctl status wol

Testing WOL

Installing gWakeOnLan

Download gwakeonlan on a different computer running Ubuntu or use WSL.

Navigate to the downloads folder and run

sudo dpkg -i ~/<downloads>/<filename>.deb

where <downloads> is the folder with the downloaded file and <filename> is the name of the file.

Finding MAC address

To find the MAC address of the target computer run

ip addr show

Against your NIC name you should find a sequence of the format FF:FF:FF:FF:FF:FF. Copy this.

Listening for the MagicPacket

On the computer you want to turn on, run the following

sudo tcpdump -UlnXi <name> ether proto 0x0842 or udp port 9 2>/dev/null | grep -P '((25[0-5]|(2[0-4]|1[0-9]|[1-9]|)[0-9])(\.(?!$)|$)){4}'

where <name> is the name of the NIC. You should see 1 line of output per Magic Packet received with IP address of the device sending the packet.

Note: If your router supports sending Magic Packets you can send it on startup of the router and skip the following.

Setting up WOL on ESPHome

Paste the following to you ESPHome's yaml file.

Adding a Button

# HA Server
- platform: wake_on_lan
id: "start_server"
name: "Start the Server"
target_mac_address: <MAC>

where <MAC> is the MAC address of the computer you want to turn on.

Configuring ESPHome to press the button on Startup

# ...
priority: 800
- wait_until:
- "start_server"

where ... represents additional configuration you may already have.

Save and install the code.

You can now test by listening for the Magic Packet by pressing the button manually and then by turning off and on both the server and ESPHome (turn off and on the main supply).