Wake On Lan Howto

More of primer for another server I use for development that I want to hibernate when not using to save energy. Plus I'm too lazy to switch the darn thing on and off..

$ ip a

 eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 6c:4b:90:03:9c:9e brd ff:ff:ff:ff:ff:ff
    altname enp1s0
    inet 192.168.1.225/24 brd 192.168.1.255 scope global eno1
       valid_lft forever preferred_lft forever
    inet6 fd41:4bbf:28e6:6894:6e4b:90ff:fe03:9c9e/64 scope global dynamic mngtmpaddr noprefixroute
       valid_lft 1701sec preferred_lft 1701sec
    inet6 fe80::6e4b:90ff:fe03:9c9e/64 scope link
       valid_lft forever preferred_lft forever```
       

MAC Address.. 6c:4b:90:03:9c:9e

 $ sudo ethtool eno1
        Settings for eno1:
        Supported ports: [ TP MII ]
        Supported link modes:   10baseT/Half 10baseT/Full
                                100baseT/Half 100baseT/Full
                                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/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
        Port: MII
        PHYAD: 0
        Transceiver: internal
        Auto-negotiation: on
        Supports Wake-on: pumbg        
        Wake-on: d
        Current message level: 0x00000033 (51)
                               drv probe ifdown ifup
        Link detected: yes

The man-page for ethtool tell you what that cryptic pumbg means – the letters are different options that this interface supports for Wake-On-LAN. In this case they are:

Option Description p Wake on PHY activity u Wake on unicast messages m Wake on multicast messages b Wake on broadcast messages g Wake on MagicPacket messages There's an additional option which is what the interface was set on – d – as you can see in the last line of the output. This means Disable (wake on nothing). This option clears all previous options. I don't have many devices on my network, so I don't know that there's a lot of broadcasts, multicasts, etc. that would be waking it up all the time, but since one feature of Wake-On-LAN is that it only wakes the machine when it gets the “Magic Packet”, only the g and d options matter. Now that I knew it was supported, it was time to try it out.

~$ sudo ethtool --change eno1 wol g

Suspend to test..

``` $ sudo systemctl suspend

or if brave..
```$ sudo systemctl hibernate
$ wakeonlan -i 192.168.1.225 6c:4b:90:03:9c:9e

Create a file at /etc/systemd/system/wol.service (I think you can use another systemd sub-folder, and you can name the file anything you want, within reason, but this one seems to work well enough). In this file you put settings that look something like this:

[Unit]
Description=Enable Wake On Lan

[Service]
Type=oneshot
ExecStart = /sbin/ethtool --change eno1 wol g

[Install]
WantedBy=basic.target

Enable The Service

To enable it you can do this:

sudo systemctl daemon-reload
sudo systemctl enable wol.service

Make an alias command

alias wakeup='wakeonlan -i 192.168.1.225 6c:4b:90:03:9c:9e

Alias on server

alias snooze='sudo systemctl hibernate'

Stick them in .bash_aliases for Ubuntu.