Wake on Lan

https://www.golinuxcloud.com/wake-on-lan-ubuntu/

Does you Network Card support Wake on Lan?

Your ethernet card must support this feature for Wake-on-Lan to work. To find out if your Ethernet card supports this feature, you must first learn the name of your Ethernet interface. In the following sections, it is recommended to register the mac address for packet sending.

In Terminal, the ip address and other information are displayed with the following command:

foc@ubuntu22:~$ ip a
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: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether 30:5a:3a:0d:ac:0d brd ff:ff:ff:ff:ff:ff
    inet 192.168.1.10/24 brd 192.168.1.255 scope global dynamic noprefixroute enp2s0
       valid_lft 67502sec preferred_lft 67502sec
    inet6 fe80::40ab:d219:c23e:abfb/64 scope link noprefixroute 
       valid_lft forever preferred_lft forever

Mac address: 30:5a:3a:0d:ac:0d and enp2s0 is the computer's network interface name. To view and change the Wake-On-Lan settings, the "ethtool" package must be installed:

foc@ubuntu22:~$ sudo apt install ethtool -y

Next, find out if the network card supports wake-on-LAN:

foc@ubuntu22:~$ sudo ethtool enp2s0
Settings for enp2s0:
...
 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 expression “Wake-on:d” indicates that the wake-on-lan feature of the network card is supported but deactivated.

Enable Wake on Lan Feature

Run the following commands to enable wake-on-lan on your network card:

foc@ubuntu22:~$ sudo ethtool -s enp2s0 wol g
Settings for enp2s0:
...
 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: g
 Link detected: yes

Some motherboard manufacturers require you to change the settings in the BIOS to enable this feature. If there is no change when you check after entering the command, it is recommended to look at the BIOS settings.

Auto Wake-On-Lan Activation at Startup

If the Wake-on-Lan settings are deactivated when the server is restarted; you should solve this problem with systemd.

Create systemd service:

foc@ubuntu22:~$ sudo --preserve-env systemctl edit --force --full wol-enable.service
[Unit]
Description=Enable Wake-up on LAN

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

[Install]
WantedBy=basic.target

Replace the enp2s0 value with your own network interface value. Then reload and enable the service:

foc@ubuntu22:~$ sudo systemctl daemon-reload

foc@ubuntu22:~$ sudo systemctl enable wol-enable.service
Created symlink /etc/systemd/system/basic.target.wants/wol-enable.service  /etc/systemd/system/wol-enable.service.

Remote Ubuntu Server Wake Up

The above steps were the steps to do for Ubuntu to wake up. Now, let's talk about the steps to be done on the server that will do the wake-up task.

One of the following package must be installed on the server in question:

foc@ubuntu22:~$ sudo apt search wakeonlan

wakeonlan/jammy 0.41-12.1 all
  Sends 'magic packets' to wake-on-LAN enabled ethernet adapters

Install wakeonlan package:

foc@ubuntu22:~$ sudo apt  install wakeonlan -y

Wake up remote server using this package:

foc@ubuntu22:~$ sudo wakeonlan 30:5a:3a:0d:ac:0d
Sending magic packet to 255.255.255.255:9 with 30:5a:3a:0d:ac:0d

Remote server mac address should be written after wakeonlan command.

Last updated