Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

总结几点Wake On Lan(WOL)失败的原因 #124

Open
Bpazy opened this issue Jul 25, 2019 · 1 comment
Open

总结几点Wake On Lan(WOL)失败的原因 #124

Bpazy opened this issue Jul 25, 2019 · 1 comment

Comments

@Bpazy
Copy link
Owner

Bpazy commented Jul 25, 2019

正文

在我想使用Wake On Lan(后文皆用WOL代替)这项技术远程开机时,总是失败,在查阅各种资料后成功使用上了WOL,下面总结几点导致失败的原因。

  1. 发送Magic Packet(魔法数据包),不多阐述,如果是编程发包,请使用UDP封包。
  2. 在BIOS中开启WOL,在我的其中实验设备的BIOS中,它的全名为“Wake On Lan In S5”。
  3. 系统层面。Win7没有官方支持WOL,但是依托于网卡的WOL,可以成功唤醒。Win8及以上的系统(我本人Win10)有很大的区别点,就在于快速启动这个功能。快速启动将计算机置于S4状态中(正常关机是S5)[1],而WOL仅在S5提供支持,所以需要关闭“快速启动”[2]。这一点在不同的计算机上可能有区别,我的硬件仅支持WOL On S5,据我了解Mac仅支持WOL On S0(S3)。
  4. 在正常开机状态下,关闭计算机,网卡仍保持着连接。如果这时候断开电源再恢复供电,则网卡不会重新建立连接,也就不能远程唤醒。所以请保持住关机状态下的供电。
  5. 无线网卡不支持远程唤醒,请使用有线网卡。

以上几点都是基于我的几台设备总结的,不排除有误,其中3、4、5三点浪费了我极久的时间调查。

参考来源

[1] ACPI电源管理介绍:https://www.cnblogs.com/AlwaysOnLines/p/4548097.html
[2] 系统层面的微软解答:https://answers.microsoft.com/en-us/windows/forum/windows_10-power/windows-10-wake-on-lan-not-working-from-shutdown/ba6ae540-b602-42f3-b5bb-afe95fe6661c

@Bpazy Bpazy added the blog label Jan 17, 2020
@Bpazy Bpazy removed the blog label Mar 22, 2020
@Bpazy
Copy link
Owner Author

Bpazy commented Nov 25, 2021

Linux 开启 Wake On Lan

前提: BIOS 支持并已开启 Wake On Lan

使用 ifconfig 找到网卡名称和 MAC 地址

root@pve:~# ifconfig
enp8s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 2c:60:0c:1c:6b:43  txqueuelen 1000  (Ethernet)
        RX packets 30406  bytes 16108731 (15.3 MiB)
        RX errors 0  dropped 1  overruns 0  frame 0
        TX packets 25080  bytes 3292961 (3.1 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

可以看到我的网卡名称为 enp8s0,然后查看网卡的 WOL 配置:

root@pve:~# ethtool enp8s0
Settings for enp8s0:
	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

注意这里的输出: Wake-on: g,如果 Wake-on 一行值为 d,表示禁用 wol,值为 g,表示启用 wol,可以看到网卡默认是禁用 wol 的,现在我们通过 ethtool 来开启::

root@pve:~# ethtool -s enp8s0 wol g

但是上面的命令有个问题,它只能临时开启 wol,重启后就被重置为 d 也就是禁用 wol 的状态了。所以我们需要新建一个 systemd service 来保证每次开机都开启 wol:

root@pve:~# cat << EOF>/etc/systemd/system/wol.service
[Unit]
Description=Enable Wake On Lan

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

[Install]
WantedBy=basic.target
EOF

root@pve:~# systemctl daemon-reload
root@pve:~# systemctl enable wol.service
root@pve:~# systemctl start wol.service

下面就重启验证吧,我这是正常的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant