How to Enable Wake-on-LAN in Ubuntu

Automate turning on your PC.

Enable Wake On Lan Ubuntu Featured

We all feel the desire to automate everything: our cars, houses and especially our computers. Wake-on-LAN is the perfect way to automate turning your PC on.

While this guide focuses on how to enable Wake-on-LAN in Ubuntu, you can apply it to Linux distros and even find the feature in Windows.

What Is Wake-on-LAN?

Wake-on-LAN or WOL is a feature that allows you to turn on your PC from another device via the network. It does this by sending a tiny “magic” packet of data from a host computer. The network driver of the receiver computer can receive this data and signal the device to power on.

How to Prepare Your Setup for Wake-on-LAN

For Wake-on-LAN to work, your Ethernet card needs to support the feature. It has been standard for at least 10 years, so chances are high your card will, but it is always good to double-check.

Your Ethernet interface is the network card of your device. Every card has a unique name found with the following terminal command:

ip a

The name you’re looking for is similar to “enp8s0.” This was the unique ID of the network card used in this tutorial.

Wake-on-Lan

Ethtool is an open-source application that allows you to change network driver settings. For wake-on-LAN, it will allow your PC to understand the data it’s receiving.

The command to install ethtool is:

sudo apt install ethtool

The tool is also available on pkgs.org if you encounter issues installing from the terminal.

Next, find out whether your network card supports wake on LAN.

sudo ethtool <Your interface name>

You’ll be given detailed information on your Ethernet interface hardware. We are looking for:

Supports Wake-on: g
Wake-on: g

The first line tells you whether your PC supports Wake-On-LAN. There might be other letters along with the g. For now, we only need the “g.”

The second line shows whether Wake-On-LAN is enabled. Don’t worry too much about that, as our next task will be to enable it.

Enable Wake-on-LAN

The command to enable Wake-on-LAN is as follows:

sudo ethtool --change <Your ethernet interface name> wol g

This will enable the service and allow your PC to be turned on by a network device. To power on the device using this feature, type the following in terminal, Windows PowerShell or command prompt.

wakeonlan -i <IP Address> <MAC Address>

This will enable it to power on once via a magic packet. However, the service doesn’t turn on on startup and is disabled after the first time. Ideally, you want to be able to power it on every time.

Automating Wake-on-LAN

First, you need to find where ethtool is installed. This terminal command will do that.

which ethtool

Secondly, you need to create a file that enables the service on boot. You can do this in your favorite text editor and place the file in “/etc/systemd/system/.”

The contents of the file should be:

[Unit]
Description=Enable Wake On Lan
 
[Service]
Type=oneshot
ExecStart = <Your filepath> --change <Your ethernet interface name> wol g
 
[Install]
WantedBy=basic.target

The vital bit in this section is the service and install parts. Oneshot is the default type parameter. It means that your service manager (systemd in Ubuntu) will execute the commands once sequentially, which is perfect because you want to change your wake-on-LAN setting to go once.

The install section tells systemd that your WOL service should run on the first level. The concept of levels, grouping, and how the system manager works is another rabbit hole, but all you need to know for now is that it will start on boot.

An issue you may run into in this section is permissions. By default, Ubuntu will not allow you to add files to the systemd folder. You can change this using chmod. You will need to have read and write permissions.

Final Steps

The final step is to restart daemon and enable the service. This will happen automatically if you restart your system, but it is quicker to do it in the terminal.

sudo systemctl daemon-reload
sudo systemctl enable wol.service

Systemctl controls systemd, and daemons are essentially helper applications. What you’re doing here is restarting the supervisor, so that detects the new file in the systemd folder.

You can check whether the service is running using:

systemctl status wol

Wireless Wake-on-LAN

Now you can turn on your PC via LAN, but what about wireless wake-on-LAN or woWLAN? As of this article, there is only one snap application (network-manager) that allows you to do this.

You can install this from the snap store or the terminal using the following command:

sudo snap install network-manager
Wake On Lan Snap Store

Beware, as this application is only rated one star in the store. During testing, the application ran as expected in the terminal, and it has full-length documentation by Canonical.

You can attempt to enable woWLAN using another network manager, but the default (networkd) has no method of enabling it.

You can enable wireless wake-on-LAN using this command:

sudo snap set network-manager wifi.wake-on-wlan=magic

If you’re on an open network or wary of security threats, you can set a password using:

sudo snap set network-manager wifi.wake-on-wlan-password=<Your password>

There are some advantages to using this method over ethtool. It’s quicker to install and allows wireless wake-on-LAN. It has kernel level access, so if the computer loses power, you can still use wake-on-LAN when power returns.

The issue is that Canonical only recommends it for Ubuntu core users. There is no specific reason for this, but it’s likely to keep the application contained and to prevent users from breaking their OS.

Frequently Asked Questions

Can I power down my PC using Wake-on-LAN?

You can only wake your PC from standby or a power-off state. There are methods of doing this, and they do not use wake-on-LAN.

Is it a security risk to enable Wake-on-LAN?

Only devices on the same network can power on your device using wake-on-LAN. Ubuntu also requires you to authenticate after powering on. As long as you avoid unsafe Wi-Fi networks, it is safe to enable wake-On-LAN.

After my device lost power, Wake-on-LAN no longer works. How can I fix this?

Ethtool does not persist when power is lost. Logging in again should re-enable the service. If you used the network-manager method, it will persist when you lose power.

Image credit: Technician team connect cable wire network to router by 123RF

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox