Enable Wake on lan ( WoL ) on NUC device

Enable Wake on lan ( WoL ) on NUC device

Wake Your NUC Device Over LAN for Seamless Remote Access


使用情境

因為部門需求,會使用到多台 NUC,想要研究如何透過網路喚起狀態處於關機的 NUC,後來看到有關於 Wake on Lan 的概念。透過區域網路內的另一台電腦對其傳遞 magic packet 後,讓該 NUC 能夠開始進行開機(或喚醒)的程式。

NUC

新一代運算單元(*NUC*,Next Unit of Computing)是一款外型小巧的計算元件,又可稱作「迷你電腦」。 — ASUS 介紹

Wake on Lan

Wake-on-LAN,簡稱WOL或WoL,中譯為「網路喚醒」、「遠端喚醒」,是一種遠端喚醒技術及標準,功效在於讓休眠狀態或關機狀態的電腦,透過區域網路的另一台電腦對其發令,使其喚醒、恢復成運作狀態,或從關機狀態轉成開機狀態。 — Wiki

Magic packet

魔法封包(Magic Packet)是一個廣播性的訊框(frame),透過埠7或9傳送,可以使用非連接導向(Connectionless protocol)的通訊協定(如UDP、IPX)來傳遞,目前鑑於已很少採用Novell NetWare網路作業系統的IPX協定而多選用UDP。


基本資訊

我所使用的 NUC 版本及系統資訊如下:

  • Product Name:NUC13ANH-B

  • BIOS Vendor:Intel Corp.

  • BISO Version:ANRPL357.0032.2024.0411.1047


設定手順

我設定了兩台 NUC,一台是 Windows 11 Pro,一台是 Debian GNU/Linux 12 (bookworm),因為兩台 NUC 型號一樣,所以 BIOS 設定也一樣,僅差在作業系統上的不同導致網卡的設定方式也不一樣。

BIOS 設定

  1. 開機時,按著 F2 以進入 BIOS 設定,點選上方的 Power, Performance and Config 頁面後,點進頁面內的 Secondary Power Settings 連結。

  1. 在 Secondary Power Settings 設定中,將 Wake on LAN from S4/S5 選項透過下拉式選單選定為 Power On - Normal Boot

  1. 最後按 `F10` 存檔並離開 BIOS 設定頁面。

在 Debian GNU/Linux 12 設定網卡

確認目前有線網卡

透過 /sys/class/net,可以檢視每個網路介面的名稱,以及其對應的設備路徑(device path),這些資訊是透過符號連結(symbolic links)所映射的。

ls -l /sys/class/net
total 0
-rw-r--r-- 1 root root 4096 Jan 17 10:59 bonding_masters
lrwxrwxrwx 1 root root    0 Jan 17 10:59 enp86s0 -> ../../devices/pci0000:00/0000:00:1d.0/0000:56:00.0/net/enp86s0
lrwxrwxrwx 1 root root    0 Jan 17 10:59 lo -> ../../devices/virtual/net/lo
lrwxrwxrwx 1 root root    0 Jan 17 10:59 vmbr0 -> ../../devices/virtual/net/vmbr0
lrwxrwxrwx 1 root root    0 Jan 17 11:02 wlo1 -> ../../devices/pci0000:00/0000:00:14.3/net/wlo1

確認網卡使否支援 Wake-on

透過 ethtool 可以查詢特定網卡是否有支援 Wol,請參考下方執行結果中兩個欄位。

  • Supports Wake-on

  • Wake-on

ethtool enp86s0
Settings for enp86s0:
    Supported ports: [ TP ]
    Supported link modes:   10baseT/Half 10baseT/Full
                            100baseT/Half 100baseT/Full
                            1000baseT/Full
                            2500baseT/Full
    Supported pause frame use: Symmetric
    Supports auto-negotiation: Yes
    Supported FEC modes: Not reported
    Advertised link modes:  10baseT/Half 10baseT/Full
                            100baseT/Half 100baseT/Full
                            1000baseT/Full
                            2500baseT/Full
    Advertised pause frame use: Symmetric
    Advertised auto-negotiation: Yes
    Advertised FEC modes: Not reported
    Speed: 100Mb/s
    Duplex: Full
    Auto-negotiation: on
    Port: Twisted Pair
    PHYAD: 0
    Transceiver: internal
    MDI-X: off (auto)
    Supports Wake-on: pumbg
    Wake-on: g
        Current message level: 0x00000007 (7)
                               drv probe link
    Link detected: yes

啟用 WoL

為確保 WoL 在系統啟動時啟用,透過以下步驟進行配置:

  1. 編輯網絡配置文件 /etc/network/interfaces,將 post-up /sbin/ethtool -s enp86s0 wol g 添加到目標網卡(我的案例是enp86s0) 的配置裡。

     auto lo
     iface lo inet loopback
    
     iface enp86s0 inet manual
    
     auto vmbr0
     iface vmbr0 inet static
         address 10.10.10.30/24
         gateway 10.10.10.254
         bridge-ports enp86s0
         bridge-stp off
         bridge-fd 0
         post-up /sbin/ethtool -s enp86s0 wol g
    
     iface wlo1 inet manual
    
     source /etc/network/interfaces.d/*
    
  1. 重新加載網路服務

     sudo systemctl restart networking
    

配置開機啟用 WoL

  1. 直接建立系統服務去 handle,創建一個 service file

     sudo nano /etc/systemd/system/wol.service
    
  1. /etc/systemd/system/wol.service 內容

     [Unit]
     Description=Enable Wake-on-LAN on enp86s0
     After=network.target
    
     [Service]
     Type=oneshot
     ExecStart=/sbin/ethtool -s enp86s0 wol g
    
     [Install]
     WantedBy=multi-user.target
    
  1. 保存文件並啟用服務

     sudo systemctl daemon-reload
     sudo systemctl enable wol.service
     sudo systemctl start wol.service
    

在 Windows OS 設定網卡

直接參考這幾篇即可:


使用 wakeonlan 喚醒 PC

因為我使用的是 MacBook,因此筆記將以如何透過 MacBook 操作 wakeonlan 工具作為範例。

使用 Homebrew 安裝 wakeonlan 工具

brew install wakeonlan

確認 MAC Address

執行以下指令找到 Physical Address

Debian

ip link show enp86s0

Windows

ipconfig /all

使用 wakeonlan 發送 Magic Packet

假設 NUC mac address 為 00:1A:2B:3C:4D:5E,需要確保幾件事:

  1. 要確保你的 MacBook 與目標 NUC 在同一個網段。

  2. 請加上 -i 指定你目前網段的廣播位置,假設是 10.10.10.0/24,10.10.10.255 就是該網段的廣播位置。

wakeonlan -i 10.10.10.255 00:1A:2B:3C:4D:5E

:' ### execute result
Sending magic packet to 10.10.10.255:9 with payload 00:1A:2B:3C:4D:5E
Hardware addresses: <total=1, valid=1, invalid=0>
Magic packets: <sent=1>
'
  1. 這樣目標 NUC 就會被喚醒了,打完收工。