How to Set Up Wake-on-LAN (WOL) on Ubuntu

Step 1: Create a Startup Script

First, create a new script file called wol_startup.sh

sudo nano /usr/local/bin/wol_startup.sh

Copy and paste the following lines into the file

#!/usr/bin/zsh

sleep 10  # Optional: Wait for 10 seconds to ensure the network is ready

/usr/sbin/ethtool -s enp1s0 wol g

Note: This script waits for 10 seconds (optional) after startup and then runs the ethtool command to enable Wake-on-LAN.

Step 2: Create a systemd Service

Next, create a new systemd service file called wol_startup.service

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

In the text editor, copy and paste the following content

[Unit]
Description=Configure Wake On LAN at Startup
After=network.target

[Service]
ExecStart=/usr/local/bin/wol_startup.sh

[Install]
WantedBy=default.target

Note: This service file will run the wol_startup.sh script to set up Wake-on-LAN.

Step 3: Enable the Service

Save and close the file

Run this command to enable your new systemd service

sudo systemctl enable wol_startup.service

Fayoo Wang

Fayoo Wang