How to enable Wake On LAN in Ubuntu Server 18.04 / Debian based systems / Systemd

How to enable Wake On LAN in Ubuntu Server 18.04 / Debian based systems / Systemd

What you’ll need

The only things you’ll need to make this work are:

  • An instance of Ubuntu Server 18.04
  • A user account with sudo privileges
  • A network interface that supports WOL

How to install ethtool

The tool that makes this possible is ethtool. Chances are, it’s already installed on your server. However, on the off-chance it’s not, let’s install it. Open a terminal window and issue the following command:

sudo apt-get install ethtool -y

How to locate the interface name

The next thing you need to do is locate the interface name you want listening for the magic packet. If your machine has both WAN and LAN interfaces, you’ll probably only want to enable this on the LAN side. 

To find the interface name, issue the command:

ip a

You should see the interface listed. Look for the name associated with IP address you want to be listening for the magic packet (Figure A).

Figure A

wola.jpg
My LAN-facing interface is ens5.

With the interface name in hand, issue the command:

sudo ethtool -s INTERFACE wol g

Where INTERFACE is the name of the interface to be used.

The command will report nothing back–unless it turns out your network interface doesn’t support WOL, at which point it will inform you as such.

Finally, you must know the MAC address of the interface. This can be discovered with the same command used to find the interface name (ip a). 

How to install WOL and send the magic packet

The easiest way to send the magic packet (from Linux to Linux) is by using another tool, called wakeonlan. Install this with the command:

sudo apt-get install wakeonlan -y

Once that application is installed, you can then send the magic packet to the listening interface with the command:

wakeonlan MAC

Where MAC is the MAC address of the LAN interface with WOL enabled. The command will report that it has sent the magic packet to the MAC address and your remote server should now be awake, allowing you to log in remotely.

Making it stick

The problem with this method is that the enabling of WOL on the interface will not stick after a reboot. To make this persistent on Ubuntu Server 18.04, you must write a systemd file. To do this, issue the command:

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

In that file, paste the following:

[Unit]
Description=Configure Wake On LAN

[Service]
Type=oneshot
ExecStart=/sbin/ethtool -s INTERFACE wol g

[Install]
WantedBy=basic.target

Where INTERFACE is the name of the interface to be used.

Save and close the file. Make systemd aware of the new script with the command:

sudo systemctl daemon-reload

Enable the new service with the command:

sudo systemctl enable wol.service

Finally, start the service with the command:

sudo systemctl start wol.service

And that’s it. Wake On LAN is now available for the LAN interface. You can wake that server without having to trudge all the way to your data center. Just remember, you have to know the MAC address of the target LAN interface, you cannot do this via IP address. Happy waking.

https://www.techrepublic.com/article/how-to-enable-wake-on-lan-in-ubuntu-server-18-04/

Comments are closed.