How to Enable Wake-on-LAN on Ubuntu

In this guide, we will be showing you how to enable Wake-on-LAN on the Ubuntu operating system.

Ubuntu enable Wake-on-LAN

Wake-on-LAN is a special functionality that allows other devices to wake your device remotely.

It allows this functionality by setting your Ubuntu devices network driver to accept a specially formatted packet called the “magic packet”.

You can also enable the Wake-on-LAN functionality through your devices BIOS. It is often called “Wake up on LAN” or “Wake up on PCI event” but your BIOS may have it named something differently.

The steps we will be covering below will show you how you can use Ubuntu to enable Wake-on-LAN support. There are two methods for achieving this. One is to use NetworkManager. The other method is to utilize ethtool.

Another thing that you should note is that typically, Wake-on-LAN is only supported over an ethernet connection.

Using NetworkManager to Enable Wake-on-LAN On Ubuntu

In this section, we will show you how to use NetworkManager on Ubuntu to enable Wake-on-LAN. This is probably one of the easiest ways to enable this functionality. However, it will only work with Ubuntu Desktop.

If you are using Ubuntu server, you must use our alternative method. NetworkManager is not used on the server editions of Ubuntu.

Determining the Right Network Interface

1. Before enabling Wake-on-LAN on your Ubuntu device, we must find the correct network adapter and retrieve its connection name.

The nmcli tool allows us to list the available network connections using the following command easily.

nmcli connection show

2. After running the above command, you will see a list of the available connections. There are two things you want from here.

First is the connection name, which in our case “Wired connection 1“. We will also want the device name, which is the last column. In our example this means our network adapters device name is “enp1s0“.

NAME                UUID                                  TYPE      DEVICE 
Wired connection 1  fd179af5-6b4d-35aa-97c4-3e14bfe9ee81  ethernet  enp1s0 

Retrieving the Network Adapters MAC Address

3. The first thing we can do is retrieve the MAC address for the ethernet adapter.

The MAC address is where we will send the Wake-on-LAN magic packet to our Ubuntu device. Replace “<DEVICE NAME>” with the name of your device.

By piping the contents of the command to grep, we can grab only the relevant lines.

nmcli device show "<DEVICE NAME>" | grep "GENERAL.HWADDR"

4. Below, you can see the result you should get after running the above command.

The value next to the “GENERAL.HWADDR” label is the MAC address for your network adapter. This is the address you will use to wake your Ubuntu device.

GENERAL.HWADDR:                         52:54:00:87:6C:0B

Checking the Wake-on-LAN Setting

5. Our next task is to retrieve the current Wake-on-LAN setting for our chosen connection.

To grab the current setting, you will want to use the following command within the terminal. Ensure you replace “<CONNECTION NAME>” with the name you retrieved in step 1.

nmcli connection show "<CONNECTION NAME>" | grep 802-3-ethernet.wake-on-lan

6. With the result below, we can tell that Wake-on-LAN is currently disabled on our Ubuntu device.

802-3-ethernet.wake-on-lan:             default
802-3-ethernet.wake-on-lan-password:    --

Using NMCLI to Enable Wake-on-LAN on Ubuntu

5. Now that you know your network connection name, you can enable Wake-on-LAN on your Ubuntu device.

enable Wake-on-LAN for this particular network connection, you will want to run the following command. You must replace “<CONNECTION NAME>” with the name of your connection.

nmcli connection modify "<CONNECTION NAME>" 802-3-ethernet.wake-on-lan magic

Turning off Wake-on-LAN

6. If you have decided you no longer want Wake-on-LAN functionality on your Ubuntu device, you simply need to use the following command.

This command changes the “Wake-on-Lan” functionality from “magic” packet to “ignore“. By setting it to ignore, your Ubuntu device will ignore any magic packets it receives on your network connection.

nmcli connection modify "<CONNECTION NAME>" 802-3-ethernet.wake-on-lan ignore

Enabling Wake-on-LAN on Ubuntu using ethtool

For those running a variant of Ubuntu without NetworkManager you will need to use a different method to enable Wake-on-LAN.

In this section, we will be exploring how you can use the program called “ethtool” to enable Wake-on-LAN on your Ubuntu device.

Installing the Required Software

1. Your first task is to update the package list and upgrade any out-of-date packages.

It is possible to perform both tasks by using the following two commands.

sudo apt update
sudo apt upgrade -y

2. Next, we can ensure that the “ethtool” program is installed on our system. This tool is what we will be using to enable Wake-on-LAN on our Ubuntu device.

To install this program, you will want to use the following command.

sudo apt install ethtool

Finding the Correct Network Adapter on Ubuntu

3. Before we can enable Wake-on-LAN using Ethtool, we will need to get the name of the network adapter.

The easiest way to do this is to use the “ip” command and have it print out all network adaptors by using the “a” option.

ip a

4. From this, you will get a relatively extensive list of values. You will need to try and use this to identify your ethernet connection.

Depending on the version of Ubuntu you are using, the adapter will either start with “eth” or “enp“. You can also see which network device has been assigned an IP address.

In our case, we can see our ethernet device name is “enp1s0” which is the value we would use over the next few sections.

2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 52:54:00:87:6c:0b brd ff:ff:ff:ff:ff:ff
    inet 192.168.0.8/24 brd 192.168.0.255 scope global dynamic noprefixroute enp1s0
       valid_lft 65733sec preferred_lft 65733sec

Checking whether Wake-On-LAN is Supported

5. Before we proceed, we should check whether our ethernet device supports Wake-on-LAN.

To check this, you must use the following command within the terminal. You must replace “<DEVICE NAME>” with the name you got in the previous step.

sudo ethtool "<DEVICE NAME>" | grep "Wake-on"

6. Below is an example of what you should see after running this command. You should see whether Wake-On-LAN is supported.

If see the letter “g” in the supported list, we can enable the magic packet method for waking up your Ubuntu device.

  • Supports Wake-on: This label lists out the Wake-on-LAN modes that your Ubuntu devices network adapter supports.
    • d: Disabled
    • p: PHY Activity
    • u: Unicast Activity
    • m: Multicast Activity
    • b: Broadcast Activity
    • a: ARP Activity
    • g: Magic Packet Activity
  • Wake-on: Here, you will see the Wake-on-LAN mode that is currently set. In our case, it is set to “d“, meaning it is disabled.
        Supports Wake-on: pumbag
        Wake-on: d

Turning on Wake-On-LAN on your Ubuntu Device

7. At this point, we can finally enable Wake-on-LAN on Ubuntu by using the following command in the terminal.

This command sets the wake feature from disabled to “g“, which allows it to listen for the magic packet.

sudo ethtool -s "<DEVICE NAME>" wol g

The only downside with this method is that this setting will not stick when your Ubuntu device restarts.

Ensuring Wake-on-LAN Is Enabled at Startup

8. To ensure that Wake-on-LAN remains on between reboots of your Ubuntu device, we need to create a service file.

This service will run at startup and ensure that Wake-on-LAN has been enabled.

You can begin writing this service file by running the following command in the terminal.

sudo nano /lib/systemd/system/wakeonlan.service

9. Within this file, you must enter the following lines. While typing this out, you will need to replace “<DEVICE NAME>” with the name given to your ethernet network adapter.

By setting the type to “oneshot“, we ensure that the service manager will only run this service once at start-up and not continually attempt to execute the command.

[Unit]
Description=Enable Wake On Lan

[Service]
Type=oneshot
ExecStart=/usr/sbin/ethtool -s <DEVICENAME> wol g

[Install]
WantedBy=basic.target

10. Once you have finished adding the above lines, save and quit by pressing CTRL + X, Y, and then the ENTER key.

11. Now that we have created a new service file, we must enable it so the system will run it at start-up.

You can enable this new service by running the following command.

sudo systemctl enable wakeonlan.service

Conclusion

Hopefully, at this point in the guide, you will have successfully enabled Wake-on-LAN On your Ubuntu device.

This functionality lets you wake your device remotely by sending a specially formatted packet to the network interface.

Please comment below if you have any issues or questions about enabling this functionality on Ubuntu.

If you found this tutorial to be helpful, we recommend checking out our other Ubuntu guides.

Leave a Reply

Your email address will not be published. Required fields are marked *