在CentOS 7上设置Wake On LAN(WOL)

时间:2020-03-21 11:47:02  来源:igfitidea点击:

在CentOS 7服务器上设置LAN唤醒。

安装

安装ethtool实用程序:

# yum install -y ethtool

配置

确保将BIOS配置为使用唤醒局域网。

检查以太网卡支持哪种WOL(我们使用net.ifnames = 0):

# ethtool eth0 | grep Wake-on
	Supports Wake-on: g
	Wake-on: d

以太网卡支持唤醒:g。
从手册页:

wol p|u|m|b|a|g|s|d...
 Sets Wake-on-LAN options. Not all devices support this. The
 argument to this option is a string of characters specifying
 which options to enable.
p Wake on PHY activity
u Wake on unicast messages
m Wake on multicast messages
b Wake on broadcast messages
a Wake on ARP
g Wake on MagicPacket™
s Enable SecureOn™ password for MagicPacket™
d Disable (wake on nothing). This option clears all previous options.

我们的卡支持MagicPacket。
配置NIC以在MagicPacket上唤醒:

# ethtool -s eth0 wol g

检查确认:

# ethtool eth0 | grep Wake-on
	Supports Wake-on: g
	Wake-on: g

通过将以下行添加到文件'/etc/sysconfig/network-scripts/ifcfg-eth0'中,使更改持久化:

ETHTOOL_OPTS="-s ${DEVICE} wol g"

将服务器挂起到内存

抓住网卡的MAC地址,将需要发送MagicPacket:

# cat /sys/class/net/eth0/address

通过systemd将系统挂起到内存:

# systemctl start systemd-suspend.service

发送一个魔术包

在另一台服务器上,安装wakeonlan软件包并将MagicPacket发送到CentOS服务器的MAC地址,例如:

$wakeonlan 00:11:22:00:00:00

确保防火墙允许广播流量离开。