未分类 · 2022年4月9日 0

Ubuntu系统的电脑设置WOL开机

因为我们一般使用的都是Windows系统,主板设置WakeOnLan(WOL)打开Enable以后就自动生效了。而在Ubuntu下则无法唤醒,很费解。

首先“ip a”查看网卡名称(还有很多命令可以查,ifconfig等等等等不一一列举)

例如我这里网卡名是enp2s0,那么继续“sudo ethtool enp2s0”,找到Wake-on这一项,后面的字字母是d或者g。d就是禁用(未开启),g则是开启。我这里是d。
对于没有ethtool的,先安装吧:sudo apt install ethtool

既然没打开,那我们就先打开它:sudo ethtool -s enp2s0 wol g

再次sudo ethtool enp2s0查看,Wake-on已经变成g了。

关机测试,WOL开机成功。

然而,再关机后,发现,又没有反应了。手动开机,命令行sudo ethtool enp2s0。MD!Wake-on又变成d了。

也就是说要每次开机都执行一次开启命令,不然就又关了。但总不能让我手动每次输入吧,就算是复制粘贴也的记得弄才行呀,忘了咋办。真麻烦。

要不写个脚本如何。算了,就一句命令,还写什么脚本,直接写进service吧

sudo gedit  /etc/systemd/system/wakeonlan.service

[Unit]
Description=Wake On Lan
[Service]
ExecStart=ethtool -s enp2s0 wol g
Restart=on-failure
Type=simple
[Install]
WantedBy=multi-user.target

然后sudo systemctl enable wakeonlan.service搞定。