Imagine
Let’s suppose you are on a delegation equipped with your handy laptop but suddenly you need access to the data from recent project residing on your main desktop at your homeLAB. Moreover, the issue is the energy. You don’t want to warm up the atmosphere or waste energy in vain for a computer tha is in use just for few minutes. So what to do? First, you need to connect to your local or office (that is not the issue of this post) network then you need to trigger the switch button to turn on your computer. But the hell! How you can to that remotely? The answer is the “Wake-on-Lan” mechanism.
WoL in short
For short Wake-on-LAN (WoL) is a feature in which a PHY network card in a very low power state can be awakened by a host using a uniquely formatted packet called a magic packet. This requires decoding a magic packet and alerting a board controller by asserting an interrupt pin when a packet match is detected - this will start your computer. How this happens? Install wakeonlan tool and then execute the command. This command sends famous “magic packet”.
sudo wakeonlan [$mac_address of computer you want to wakeUP]
Sending magic packet to 255.255.255.255:9 with [$mac_address]
It is a wired network interface case. On a wifi network interface, WoL can be enabled too but slightly different.
but before
The basic requirement is to have the WoL functionality enabled in UEFI. This option needs to be enabled: PCIe Device Power On
Having that, WoL needs to be enabled in Linux kernel. Ethtool will be indispensable in order to verify this. Execute:
sudo ethtool [your active network intefrace name]
if in the output you see this line: Wake-on: g
you are good if you see this: Wake-on: d
execute the command: ethtool -s %i wol g
where i%
is the name of your active network interface. Now you are ready to wake up your computer remotely but only once. After you start your computer again the procedure needs to be repeated. Yeap, you need to automate this and do this persistent every time you turn on a computer.
WoL persistent
go to: /etc/systemd/system
use sudo and touch the file [email protected]
and put into what follows:
[Unit]
Description=Wake-on-LAN for %i
Requires=network.target
After=network.target network-online.target
[Service]
Restart=on-failure
RestartSec=10s
ExecStart=/usr/bin/ethtool -s %i wol g
Type=simple
[Install]
WantedBy=multi-user.target
Next enable the service: sudo systemctl enable [email protected]
where enp1s0
replace with your name for the network card
Next start the service: sudo systemctl start [email protected]
Almost done but after the reboot, service still not triggers Wake-on: g
on your network interface? Here is the catch: TLP - subsytem optimizing Linux laptop battery life. Sounds funny because I’m not on a laptop, and batter life doesn’t matter in this case. Any way TLP is installed by default. Now, what needs to be done? Go to: /etc/tlp.conf
and add the line there:
WOL_DISABLE=N