ubuntu22.04网络唤醒

2022-09-16  本文已影响0人  超人不会Fly
  1. 安装 ethtool
sudo apt install ethtool

2.查看网卡名,使用 ip a 命令,看到自己的IP地址那一行的最后一个就是网卡名,这边显示为 eno1

inet 192.168.50.175/24 brd 192.168.50.255 scope global dynamic noprefixroute eno1

3.网络唤醒服务配置
正常使用时会发现每次开机后都要重新设置网卡的状态才能在下一次关机后再次使用网络唤醒,所以我们可以通过systemd添加一个系统服务在每次开机后修改网卡状态,具体做法如下:
先确定ethtool的绝对路径

ubuntu@ubuntu-Series:~$ which ethtool
/usr/sbin/ethtool

这里我的工具路径是/usr/sbin/ethtool, 之后可以创建一个 /etc/systemd/system/wol.service 文件,在这里写下启动执行一次的服务信息

[Unit]
Description=Configure Wake On LAN

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

[Install]
WantedBy=basic.target

需要注意网卡名为eno1,ethtool的路径是/usr/sbin/ethtool,对于不同网卡,可能名字不同,
之后只需要enable该服务就可以

sudo systemctl daemon-reload
sudo systemctl enable wol.service

最后可以检查一下状态

ubuntu@ubuntu-Series:~$ systemctl status wol
○ wol.service - Configure Wake On LAN
     Loaded: loaded (/etc/systemd/system/wol.service; enabled; vendor preset: enabled)
     Active: inactive (dead) since Sat 2022-09-17 20:21:46 CST; 49min ago
   Main PID: 914 (code=exited, status=0/SUCCESS)
        CPU: 2ms

9月 17 20:21:46 ubuntu-Series systemd[1]: Starting Configure Wake On LAN...
9月 17 20:21:46 ubuntu-Series systemd[1]: wol.service: Deactivated successfully.
9月 17 20:21:46 ubuntu-Series systemd[1]: Finished Configure Wake On LAN.
上一篇下一篇

猜你喜欢

热点阅读