1. 程式人生 > 實用技巧 >WOL網路喚醒 持久化配置

WOL網路喚醒 持久化配置

  1. 保證bios和網絡卡支援WOL喚醒,並關閉低功耗模式
  2. 此命令僅在Ubuntu20.04LTS上測試通過,其餘發行版同理,請自測

參考連結
https://www.techrepublic.com/article/how-to-enable-wake-on-lan-in-ubuntu-server-18-04/
https://help.ubuntu.com/community/WakeOnLan#External_Links

WOL開啟設定

~ sudo  apt-get install ethtool #安裝管理工具
~ ip a #查詢網路狀態等資訊。。。
~ sudo ethtool
-s enp1s0 wol g #使能WOL功能
~ sudo ethtool enp1s0  #查詢是否使能成功        
Settings for enp1s0:
	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 
	Link partner advertised pause frame use: Symmetric
	Link partner advertised auto-negotiation: Yes
	Link partner advertised FEC modes: Not reported
	Speed: 100Mb/s
	Duplex: Full
	Port: MII
	PHYAD: 0
	Transceiver: internal
	Auto-negotiation: on
	Supports Wake-on: pumbg
	Wake-on: g
#標誌位為 g 即已開啟WOL, d 則相反 Current message level: 0x00000033 (51) drv probe ifdown ifup Link detected: yes

WOL持久化設定(保證重新開機仍然開啟網絡卡的WOL功能)

建立一個WOL開機程序

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

寫入內容

[Unit]
Description=Configure Wake On LAN

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

[Install]
WantedBy=basic.target

使systemd知道新的WOL指令碼

sudo systemctl daemon-reload

使能WOL指令碼

sudo systemctl enable wol.service

啟用WOL指令碼

sudo systemctl start wol.service