Sunday, January 7, 2018
HowTo Enable Wake on LAN on Gentoo
HowTo Enable Wake on LAN on Gentoo
Wake-on-LAN also know as WOL is the ability to switch on a computer that is connected to a network (local or not) by means of a special network message called a magic packet. This magic packet contains the MAC address of the destination computer. If the destination computer has a network interface card that support WOL then the system wakes up.
In this post Ill describe how to setup a Gentoo destination computer so that it can be turned on from another computer.
For sake of simplicity Ive broken down the procedure into a few steps:
1) Enable WOL in BIOS
2) Install ethtool
3) Collect network interface information
4) Enable WOL for the next shutdown
5) Make WOL always enabled
6) Wake up the computer from local network
7) Wake up the computer from internet
8) Troubleshooting
1) Enable WOL in BIOS
These days pretty much all integrated or otherwise NICs support Wake-on-LAN, however more often than not youll need to enable it in the BIOS. There are literally hundreds of BIOS around but look for the typical options: "Enable Wake-on-LAN", "Enable Wake on PCI" and "Enable Power of PCIE Devices".2) Install ethtool
Take emerge for a spin and install sys-apps/ethtool. ethtool is an utility for examining and tuning ethernet-based network interfaces.# emerge ethtool
# rehash
3) Collect network interface information
To use Wake-on-LAN we need to identify the NIC MAC address. For example, in my computer the MAC address is 00:aa:11:bb:22:cc.# ifconfig
eth0 Link encap:Ethernet HWaddr 00:aa:11:bb:22:cc
inet addr:192.168.1.3 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fa10::120:1aef:ffeb:b78a/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:129199 errors:0 dropped:0 overruns:0 frame:0
TX packets:165680 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:58680158 (55.9 MiB) TX bytes:26252276 (25.0 MiB)
Interrupt:10 Base address:0xa000
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:0 (0.0 B) TX bytes:0 (0.0 B)
Check if the NIC does support the Wake-on-LAN feature:
# ethtool eth0
Settings for eth0:
Supported ports: [ MII ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Speed: 100Mb/s
Duplex: Full
Port: MII
PHYAD: 1
Transceiver: external
Auto-negotiation: on
Supports Wake-on: g
Wake-on: d
Link detected: yes
The "Supports Wake-on: g" string means that the NIC does in fact support Wake-on-LAN while "Wake-on: d" is a sign that the feature isnt active.
4) Enable WOL for the next shutdown
To command the operating system to enable WOL for the eth0 network interface run:# ethtool -s eth0 wol g
Issuing ethtool again now returns "Wake-on: g" so now we have WOL enabled:
# ethtool eth0
Settings for eth0:
Supported ports: [ MII ]
Supported link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Supported pause frame use: No
Supports auto-negotiation: Yes
Advertised link modes: 10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
Advertised pause frame use: No
Advertised auto-negotiation: Yes
Speed: 100Mb/s
Duplex: Full
Port: MII
PHYAD: 1
Transceiver: external
Auto-negotiation: on
Supports Wake-on: g
Wake-on: g
Link detected: yes
5) Make WOL always enabled
To have WOL always enabled Gentoo needs to be told that eth0 WOL is supposed to be active.Assuming yourre using OpenRC (which you should) add ethtool -s eth0 wol g to /etc/local.d/wol.start:
# echo "ethtool -s eth0 wol g" > /etc/local.d/wol.start
# chmod +x /etc/local.d/wol.start
The /etc/local.d/ directory contains scripts which are to be run when local service is started or stopped, so by adding a script with an executable script with a .start extension, it will be run when the local service is started at boot.
6) Wake up the computer from local network
From the computer that will be used to send the magic WOL packet, install and run net-misc/wakeonlan:# emerge wakeonlan
# rehash
# wakeonlan -i 192.168.1.255 00:50:8d:eb:a7:8a
Replace 192.168.1.255 with the broadcast from your network. 192.168.1.255 is the broadcast address for a 192.168.1.x subnet which is the case of my local network.
7) Wake up the computer from internet
This involves enabling port forwarding of UDP port 9 to the destination computer in the routers administration webpage. To fully benefit from WOL you should configure a dynamic DNS service.Afterwards to issue the wake up command you can use websites such as http://wakeonlan.me, Android applications (Wake on Lan) or any other Wake-on-LAN application (every Unix-like system as an alternative available). Just make sure to use your dynamic DNS provided address and the destination computers MAC.
8) Troubleshooting
While troubleshooting Wake-on-LAN Ive noticed that if you use GRUB without timeout set and poweroff the computer while on the operating system selection menu, the next time you try to use Wake-on-LAN it wont work. So make sure you have GRUB with a timeout set (which is the case will all default installation of GRUB).If the computer is disconnected from the power supply youll need to boot the computer and turn off again so that the NIC assumes the WOL definitions.