
wake on lan
我的伺服器上有設定服務。在區域網路上一切正常:
root@server$: poweroff
user@local$ wakeonlan AA:BB:CC:DD:EE:FF
伺服器醒來。
AA:BB:CC:DD:EE:FF
是 my 的 MAC 位址server
,其中包含 IP192.168.1.2
和主機名稱:example.com
。它連接到路由器,其IP為192.168.1.1(公共:xxx.xxx.xxx.xxx)
當伺服器啟動後,我可以 ping 通:
ping example.com
或透過 ssh 登入:
ssh [email protected]
到目前為止,一切都很好。現在我可以從本機喚醒伺服器,但是如何從遠端位置喚醒伺服器呢?
我嘗試過:user@local$ wakeonlan -i xxx.xxx.xxx.xxx AA:BB:CC:DD:EE:FF
,但它不起作用(什麼也沒有發生;)。
我是否必須以某種方式設定我的路由器才能轉發魔術資料包?如何?
解決方案
後拉格納的回答解決方案看起來很簡單。
但實際上,這有點棘手。
我的路由器是Linksys WAG200g
,預設不支援 LAN 喚醒。此外,它不允許轉發到上面的三元組254
(我的廣播位址是192.168.1.255
)。
解決方案是將UDP連接埠轉送到7
伺服器的位址,即192.169.1.2
,然後呼叫:
wakeonlan -i example.com -p 7 AA:BB:CC:DD:EE:FF
我還安裝了新韌體:
這是一個很棒的路由器選項升級(例如添加 LAN 喚醒選項)。
我還將我的網路遮罩從 更改為255.255.255.0
,255.255.255.128
因此我的廣播現在是192.168.1.127
並且通過了路由器驗證規則。
這是我用來連接到機器並在需要時喚醒它的腳本:
#!/bin/bash
## This sends magic packets to Wake on Lan
## please note, you must formard port 7 to the target machine on your router
## host to wake up
host="example.com"
## mac address of the machive to wake up
mac="AA:BB:CC:DD:EE:FF"
## user to login
user="administrator"
echo "Looking for $host..."
wget -q --tries=2 --wait=1 --waitretry=5 http://$host/
if [ $? -ne 0 ];
then
echo "$host is not available."
echo "Waking up $host."
wakeonlan -p 7 -i $host $mac
echo "$host is booting up. Please wait..."
sleep 30
wget -q --waitretry=5 --wait=5 http://$host/
echo ^G
echo $host is up! Lucky you!
fi
ssh "$user@$host"
不要忘記安裝:瓦克蘭
答案1
您需要將 UDP 連接埠 9 轉送到網路中的廣播位址(192.168.1.255 或類似位址)。