Sysadmin Corner 001: Wake-On-Lan Sticky Setup

2023-08-24

Picture of Street Corner Business with Sysadmin Corner on sign header graphic

Upgrade Joys and Ah-ha Moments

MX 23 Libretto is awesome! I have been running MX Linux on my Recycled Workstation at work since MX 19 so this is the second time I have upgraded to the newest version of MX Linux on this workstation. Although I have enjoyed running the MX Fluxbox edition for the last few years, I decided to switch to their flagship edition which uses XFCE as the desktop environment. So far, I’m loving the tweaks that the MX team have brought to their flavor of Debian Stable on top of XFCE. Since I took lots of notes about what I set up on my upgraded system with the move from MX Fluxbox 19 to 21, I had a good idea of what needed to be done after I did the upgrade to MX 23 Libretto.

The reason for this new post and a future post in the works comes from the realization that in the two years since I upgraded to MX 21, websites that I used to configure key features of this desktop have fallen off the Internet. So I thought I would document the tasks here in my own blog for others who might be looking for similar information.

The Magic of Wake-On-Lan

I believe it was Jay at learnlinux.tv that introduced me to the idea of using wake-on-lan so that all of the computers that I run in the homelab and at work don’t have to be one 24/7 but only when they are likely to be accessed. I use wake-on-lan to wake up my server at work every morning, and it shuts down every night so that when I’m not work, the server isn’t just being a power drain. I do the same with my storage server in the homelab, it wakes every night to backup files from my main homelab server then shuts down immediately after the backup script runs.

I like to be able to wake up my recycled workstation if I happen to be at home, and a file did not sync properly to the homelab server or I want to do some other task on my work computer. After upgrading to MX 23 I realized that the workstation would no longer wake up when the “magic packet” was broadcast over the network from my always on Raspberry Pi.

The Steps to Restore Wake-On-Lan

  1. Change MX to boot with systemd

This might be the most controversial step if you are in love with MX and appreciate that they by default boot with SysV init scripts. The method that I have found to reliably reset the network interface depends on a systemd service file running at boot. Could this be done with SysV? Yes, I’m sure that it can be done, I just don’t know how to format the script and where it would go in the system so that it is executed every time the desktop boots.

The easiest way to do this is to use the MX Boot Options utility pictured below.

MX Boot Options Utility

In the drop down box next to “Boot to” choose the latest kernel with “(systemd)”. Click “Apply” and grub will be updated with your choice, then you can close the utility. My experience in the past is that when MX installs a new kernel it remembers your choice, and automatically chooses to boot the latest kernel with systemd.

  1. Discover your network card interface name.

Wake-On-Lan only works according to my understanding with wired connections to the network. So you need to have your system connected to your network through a wired Ethernet interface. Once you have done that, you can run the following command to get the name of your network card interface which can be different from one distribution to another.

ip address

You should get some output that looks similar to what I have below.

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
    inet6 ::1/128 scope host
       valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether bc:ee:7b:dc:5b:ea brd ff:ff:ff:ff:ff:ff
    inet 10.10.1.100/24 brd 10.10.1.255 scope global dynamic noprefixroute eth0
       valid_lft 81179sec preferred_lft 81179sec
    inet6 fe80::9406:4006:fcd6:9778/64 scope link noprefixroute
       valid_lft forever preferred_lft forever

The important line is labeled “2:” where in my output I see the physical network interface is called “eth0”. You may see multiple “addresses” or “devices” if you are running container or have multiple network interfaces in your workstation. Since I don’t have a wireless card or other network interfaces I can easily tell which one has given me the ip address to my computer on the local network. Other common interface names could be “enp2s0” or “eno1” for wired interfaces or a wireless interface might be called “wlp1s0”.

  1. Check whether the network interface is capable of Wake-On-Lan.

Run sudo ethtool eth0 replacing the network card interface name with the one that fits your system. You should get similar output to what I have below.

Settings for eth0:
	Supported ports: [ TP	 MII ]
	Supported link modes:   10baseT/Half 10baseT/Full
	                        100baseT/Half 100baseT/Full
	                        1000baseT/Half 1000baseT/Full
	Supported pause frame use: Symmetric Receive-only
	Supports auto-negotiation: Yes
	Supported FEC modes: Not reported
	Advertised link modes:  10baseT/Half 10baseT/Full
	                        100baseT/Half 100baseT/Full
	                        1000baseT/Half 1000baseT/Full
	Advertised pause frame use: Symmetric Receive-only
	Advertised auto-negotiation: Yes
	Advertised FEC modes: Not reported
	Link partner advertised link modes:  10baseT/Half 10baseT/Full
	                                     100baseT/Half 100baseT/Full
	                                     1000baseT/Full
	Link partner advertised pause frame use: Symmetric
	Link partner advertised auto-negotiation: Yes
	Link partner advertised FEC modes: Not reported
	Speed: 1000Mb/s
	Duplex: Full
	Auto-negotiation: on
	master-slave cfg: preferred slave
	master-slave status: slave
	Port: Twisted Pair
	PHYAD: 0
	Transceiver: external
	MDI-X: Unknown
    Supports Wake-on: pumbg
	Wake-on: d
	Link detected: yes

The important lines are at the bottom.

	Supports Wake-on: pumbg
	Wake-on: d

If you see “g” your network interface supports wake-on-lan when it receives the “magic packet” it will boot the system.

All of the systems that I have implemented to use wake-on-lan had the last line Wake-on: d which means that currently wake-on-lan is disabled. If this already says Wake-on: g you are done, and you don’t have to do anything more because your system is already set to use wake-on-lan.

  1. Test wake-on-lan.

sudo ethtool -s eth0 wol g

The above command will setup the network interface to use wake-on-lan which you can check by running sudo ethtool eth0 again and looking for Wake-on: g. But this will only work once, you can shutdown the system now, and then from another system on the same network send the command wakeonlan bc:ee:7b:dc:5b:ea or on Fedora systems the command is wol bc:ee:7b:dc:5b:ea. As long as the MAC address matches the network interface MAC address your system should boot up.

Unfortunately, the above command will not work after the first reboot unless you would run it every time before shutting down the system which I’m sure you could do in any number of ways, but I like to use the following method.

  1. Make the wake-on-lan setting sticky by creating a systemd service file.

Using your favorite CLI text editor you would create this new service file.

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

Fill it with the following content most of which should be self explanatory.

[Unit]
Description=Activate WOL on eth0 network card
After=network-online.target
[Service]
Type=oneshot
ExecStartPre=/bin/sleep 30
ExecStart=/sbin/ethtool -s eth0 wol g
[Install]
WantedBy=basic.target

For some systems you might be able to eliminate the line ExecStartPre=/bin/sleep 30. I found that my recycled workstation network interface needed a little extra time before the network card was read to have its setting changed, so I had to add the sleep 30 command before the ethtool command.

After saving the file you can run the service file once, check the status, and then enable it so it runs every time you reboot your system. If the following command fail, it might be because you have not rebooted your MX install using systemd, do that first then try the commands below again.

sudo service wol start

sudo service wol status

sudo systemctl enable wol.service

The original author who helped me crack this task is Alberto Iriberri Andres. Here is the original blog article on the WayBackMachine .

Photo used to create the header graphic came from Unsplash photographer Bryan Papazov

ArticlesMX-Linuxterminal

Steve (mowest)

A free and open source enthusiast using these tools for work and fun.

Volley Your Files From One Computer to Another