Alright, where to begin?!
So what is the problem?
The steps for preparing Ubuntu for WoL are as follows:
- Install ethtool with:
sudo apt-get install ethtool
– Ubuntu Server 18.04 LTS already has this installed
to get the name of your network interface. Its worth noting here that all the guides I found say that “your network interface is most likely eth0”. The thing is, that’s no longer the case. Ubuntu has been transitioning to systemd since version 15.04 and part of that transition is the implementation of Predictable Network Interface Naming and so you might just find that your network interface name is something along the lines of:
to get your network interface name:
- Run the command
sudo ethtool -s interface wol g
and this tells ethtool to tell the network card to listen out for magic packets. The g denotes that it should listen for magic packets. The problem is, this solution isn’t persistent between shutdowns so once the machine is powered down and then booted up again, the setting is lost. The general consensus is that you should create a system service that runs this command at start-up.
- On Ubuntu 18.04, you need to create a systemd service as opposed to enabling, creating and/or modifying rc.local as you would’ve done on previous versions. So, navigate to
and create a new file here called `wol.service` – you could be more descriptive but I prefer short filenames, I know what wol means here. I use vim for all my terminal based editing so I run this command:
sudo vim wol.service
to create and begin editing my service file.
- Now you need to populate your wol.service file with all it needs to run as a service. The most comprehensive documentation I found on this was provided by RedHat linux here. My file looks like this:[Unit] Description=Configure Wake-up on LAN [Service] Type=oneshot ExecStart=/sbin/ethtool -s enp35s0 wol g [Install] WantedBy=basic.target ExecStart provides the command to run. It’s important to note that this must be the absolute path to ethtool because services don’d do relative paths. Check the documentation if you want to understand the file structure more thoroughly.
- Once you’ve created your file, you need to add it to the systemd services so you should run
systemctl daemon-reloadto tell the system to update and/or locate new service files, like the one we just created.
systemctl enable wol.serviceto enable the service to run on start up and,
systemctl start wol.serviceto fire up the service. This may be a redundant command but I’m not sure if step 7 does this automatically or not so there’s no harm in running it anyway.
And there we have it, if you’ve gone through all of that and enabled Wake-on-lan in BIOS, you should be able to power off your machine and then wake it up with a magic packet.
The Magic Packet
I opted to use a python script to send my magic packet, provided by San Bergmans, thank you! I had to modify it ever so slightly, maybe because I’m using it on a Mac, it expected a mac address as a parameter and it always took its own filename as the first parameter, which is obviously not a mac address, regardless of whether or not I actually provided it a parameter. I actually wen’t further than that and just dumped my mac address in file, skipped the parameter requirement and now it just sends a magic packet with my pre-defined mac address whenever I run the script. I literally type:
in my mac terminal and the magic packet is sent, the server fires up and I’m good to go! (I have the script in a directory added to path, some advise against such a practice but convenience is what I thirst for!)BOOKMARK THE PERMALINK.