Linux

從自定義路由器(樹莓派)喚醒區域網路

  • May 26, 2020

這個問題繼續

我想從我的自定義路由器(樹莓派)發送用於喚醒區域網路的魔術包。下面是網路圖片;

網路形象

我使用wakeonlan發送魔術包。然而,台式電腦並沒有被喚醒……

這是設置資訊。

Raspi(路由器) (台式電腦開機)

$ ip a
1: lo: ~~~~~
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
   link/ether b8:27:eb:df:31:9c brd ff:ff:ff:ff:ff:ff
   inet 172.16.0.20/23 brd 172.16.1.255 scope global noprefixroute eth0
      valid_lft forever preferred_lft forever
   inet6 fe80::51dd:e5ef:c061:adb9/64 scope link 
      valid_lft forever preferred_lft forever
3: wlan0: ~~~~~
4: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
   link/ether 04:ab:18:3b:af:e2 brd ff:ff:ff:ff:ff:ff
   inet 192.168.1.1/24 brd 192.168.1.255 scope global noprefixroute eth1
      valid_lft forever preferred_lft forever
   inet6 fe80::83fa:6dee:9799:9a6e/64 scope link 
      valid_lft forever preferred_lft forever
5: vpn_vpn_nic: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UNKNOWN group default qlen 1000
   link/ether 5e:ab:14:17:ae:3a brd ff:ff:ff:ff:ff:ff
   inet 192.168.0.20/24 brd 192.168.0.255 scope global noprefixroute vpn_vpn_nic
      valid_lft forever preferred_lft forever
   inet6 fe80::ebcc:65ba:a7f4:a21e/64 scope link 
      valid_lft forever preferred_lft forever
   inet6 fe80::5cab:14ff:fe17:ae3a/64 scope link 
      valid_lft forever preferred_lft forever
$ arp
Address                  HWtype  HWaddress           Flags Mask            Iface
172.16.0.91              ether   38:f9:d3:61:a4:2a   C                     eth0
172.31.68.210            ether   00:ae:43:d1:c7:a2   C                     vpn_vpn_nic
192.168.0.12             ether   5e:57:21:b5:c2:2e   C                     vpn_vpn_nic
192.168.1.19             ether   00:d8:61:56:24:2d   C                     eth1
172.16.0.1               ether   00:60:b9:7f:82:0f   C                     eth0

桌面

$ ip a
1: lo: ~~~~~~~
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
   link/ether 00:d8:61:56:24:2d brd ff:ff:ff:ff:ff:ff
   inet 192.168.1.19/24 brd 192.168.1.255 scope global noprefixroute eno1
      valid_lft forever preferred_lft forever
   inet6 fe80::2d8:61ff:fe56:242d/64 scope link
      valid_lft forever preferred_lft forever
$ sudo ethtool eno1
Settings for eno1:
Supported ports: [ TP ]
Supported link modes:   10baseT/Half 10baseT/Full
                      100baseT/Half 100baseT/Full
                      1000baseT/Full
Supported pause frame use: No
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: No
Advertised auto-negotiation: Yes
Advertised FEC modes: Not reported
Speed: 1000Mb/s
Duplex: Full
Port: Twisted Pair
PHYAD: 1
Transceiver: internal
Auto-negotiation: on
MDI-X: on (auto)
Supports Wake-on: pumbg
Wake-on: d
Current message level: 0x00000007 (7)
     drv probe link
Link detected: yes
$ arp
Address                  HWtype  HWaddress           Flags Mask            Iface
_gateway                 ether   04:ab:18:3b:af:e2   C                     eno1

Raspi(路由器) (當台式電腦關閉時)

$ ip a
~~~~
4: eth1: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
   link/ether 04:ab:18:3b:af:e2 brd ff:ff:ff:ff:ff:ff
~~~~

關閉台式電腦後,eth1與台式電腦的連接失去。

$ arp
Address                  HWtype  HWaddress           Flags Mask            Iface
172.16.0.91              ether   38:f9:d3:61:a4:2a   C                     eth0
172.31.68.210            ether   00:ae:43:d1:c7:a2   C                     vpn_vpn_nic
192.168.0.12             ether   5e:57:21:b5:c2:2e   C                     vpn_vpn_nic
172.16.0.1               ether   00:60:b9:7f:82:0f   C                     eth0

在 raspi 中喚醒區域網路命令。

wakeonlan -p 7 00:D8:61:56:24:2D

問題

  • 我應該將桌面設置eno1Wake-on: g永久嗎?
  • 我的 raspi 路由錯了嗎?
  • 儘管廣播(255.255.255.255),為什麼不能將魔術包到達桌面?我找不到原因…
  • 當台式電腦關閉時,命令中的缺失eth1是否arp正確?

回答(對於@telcoM 的回答)

  • 首先,我將桌面的乙太網設置eno1Wake-on: g. 為此,我使用network manager了因為我的台式電腦是 Ubuntu 18.04。
$ sudo vi /etc/netplan/~~~.yaml
# Let NetworkManager manage all devices on this system
network:
 version: 2
 renderer: NetworkManager

 ethernets:
   eno1:
      dhcp4: no
      wakeonlan: true <<<<<<< Newly Added
      addresses: [192.168.1.19/24]
      gateway4: 192.168.1.1
      nameservers:
        addresses: [8.8.8.8,8.8.4.4]
  • 其次,我將 BIOS 的ErP模式設置為禁用。
  • 然後,檢測到 raspi(router) eth1
4: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
   link/ether 04:ab:18:3b:af:e2 brd ff:ff:ff:ff:ff:ff
   inet 192.168.1.1/24 brd 192.168.1.255 scope global noprefixroute eth1
      valid_lft forever preferred_lft forever
   inet6 fe80::83fa:6dee:9799:9a6e/64 scope link 
      valid_lft forever preferred_lft forever
  • 最後,下面的命令讓PC喚醒,之前的問題已經完全解決了!!!
wakeonlan -i 192.168.1.255 -p 7 00:D8:61:56:24:2D

當台式 PC 關閉時,連接到它的 RasPi 的網路介面報告NO-CARRIER,或者換句話說,物理連結斷開。這意味著桌面未處於啟用 LAN 喚醒的狀態。

Wake-on: d輸出ethtool證實了這一點。d表示“什麼都不喚醒”,因此 LAN 喚醒電路不會被啟動。

是的,如果您想讓它能夠根據請求喚醒,您應該設置eno1為。Wake-on: g您可能還需要更改一兩個 BIOS 設置,以確保系統韌體允許系統喚醒。

如果您ErP在 BIOS 設置中啟用了兼容模式,則需要禁用它:ErP基本上意味著系統將完全關閉以積極最小化任何類型的待機功耗,並且通常會完全關閉 NIC,因此它不會能夠接收 LAN 喚醒數據包。

您的 BIOS 設置也可能具有專用的 LAN 喚醒設置,或者更通用的名稱,例如“Wake on PCI”。如果你的 BIOS 有類似的東西,你也應該啟用它。這也有助於確保您的桌面在例如斷電後會回到 WOL-ready 狀態,而不僅僅是在從 Linux 正常關機後。

當桌面關閉並準備好進行 LAN 喚醒時,其 NIC 應保持部分活動狀態 - 它很可能會降低連結速度以最大程度地減少功耗,但RasPi上ip a的 仍應報告UPLOWER_UPeth1並且ethtool eth1RasPi 應該說Link detected: yes

發送 LAN 喚醒數據包時,您可能必須將其定位到eth1網路的廣播地址,否則該wakeonlan命令可能無法選擇正確的介面來發送數據包:

wakeonlan -i 192.168.1.255 -p 7 00:D8:61:56:24:2D

引用自:https://unix.stackexchange.com/questions/588973