6

wake on lan – 网络唤醒电脑

 2 years ago
source link: https://xmetal.cc/?p=2091
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

1. 主板上开启

这里使用的是微星主板

  1. 高级–整合周边设备–网卡ROM启动,设置为允许
  2. 高级–电源管理设置–Erp ,设置为禁止
  3. 高级–唤醒事件设置–PCIE设备唤醒,设置为允许

2 检查主机板块和网卡是否支持Wol

检查主板是否支持

sudo apt install ethtool -y  (-y 参数是如果出现询问 默认 y)
sudo ethtool eth40ss  (eth40ss 指你的网卡可以用 ip a 或者ifconfig 查看)

如果出现一下信息, 则通过

Supports Wake-on: pumbg

Wake-on: g

如果没有则需要开启

sudo ethtool –change enp4s0 wol g

3. ubuntu 20.04设置

which ethtool # 查看命令源 我的是/usr/sbin/ethtool
  1. 设置开机启动启动 wol 服务,新建服务
sudo vim /etc/systemd/system/wol.service

编辑内容如下

[Unit]
Description=Configure Wake On Lan

[Service]
Type=oneshot
ExecStart=/sbin/ethtool --change enp43s0 wol g


[Install]
WantedBy=basic.target
#To enable it you can do this:

sudo systemctl daemon-reload
sudo systemctl enable wol.service
sudo systemctl start wol.service
#查看设置状态
systemctl status wol

2.使用netplan 永久自动开发方法

需要添加mac 地址

1network:
2version: 2
3renderer: networkd
4ethernets:
5enp2s0:
6match:
7macaddress: 50:e5:49:b3:fc:97
8dhcp4: true
9wakeonlan: true

4. 关闭服务器, 本地使用 命令 启动服务器

唤起远程服务端的客户端上需要安装

Command-line tools

unbuntu 可以安装

sudo apt install wakeonlan

wakeonlan mac地址 #唤醒电脑

mac python脚本 wol.py

01#!/usr/bin/env python
02 
03import socket
04import sys
05 
06if len(sys.argv) < 3:
07print "Usage: wakeonlan.py <ADR> <MAC>     (example: 192.168.1.255 00:11:22:33:44:55)"
08sys.exit(1)
09 
10mac = sys.argv[2]
11data = ''.join(['FF' * 6, mac.replace(':', '') * 16])
12sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
13sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
14sock.sendto(data.decode("hex"), (sys.argv[1], 9))
1python wol.py 192.168.1.255 00:11:22:33:44:55

在路由上安装

1opkg install etherwake
2 
3如果你的路由是主路由,那么要设置广播的网关段,而小米的网络段是192.168.31.255:
4/usr/bin/etherwake -D -i 'lan' "D8:BB:C1:4F:E5:12" 2>&1
5 
6如果你的路由是旁路由
7wakeonlan -i mac地址
8 
9这样通过zerotier远程连接路由器SSH,然后通过命令就可以开启局域网中的指定电脑。

Ubuntu

Post navigation

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Comment *

Name *

Email *

Website


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK