This is a guest post written by SathiyaMoorthy.
Wakeonlan (wol) enables you to switch ON remote servers without physically accessing it. Wakeonlan sends magic packets to wake-on-LAN enabled ethernet adapters and motherboards to switch on remote computers.
By mistake, when you shutdown a system instead of rebooting, you can use Wakeonlan to power on the server remotely. Also, If you have a server that don’t need to be up and running 24×7, you can turn off and turn on the server remotely anytime you want.
This article gives a brief overview of Wake-On-LAN and instructions to set up Wakeonlan feature.
Overview of Wake-On-LAN
- You can use Wakeonlan when a machine is connected to LAN, and you know the MAC address of that machine.
- Your NIC should support wakeonlan feature, and it should be enabled before the
shut down. In most cases, by default wakeonlan is enabled on the NIC. - You need to send the magic packet from another machine which is connected to the same network ( LAN ). You need root access to send magic packet. wakeonlan package should be installed on the machine.
- When the system crashes because of power failure, for the first time you cannot switch on your machine using this facility. But after the first first boot you can use wakeonlan to turn it on, if the server gets shutdown for some reason.
- WakeonLan is also referred as wol.
Check whether wol is supported on the NIC
Execute the following ethtool command in the server which you want to switch ON from a remote place.
# ethtool eth0 Settings for eth0: Supported ports: [ TP MII ] Supported link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full Supports auto-negotiation: Yes Advertised link modes: 10baseT/Half 10baseT/Full 100baseT/Half 100baseT/Full Advertised auto-negotiation: Yes Speed: 100Mb/s Duplex: Full Port: MII PHYAD: 1 Transceiver: internal Auto-negotiation: on Supports Wake-on: pumbg [ Note: check whether flag g is present ] Wake-on: g [ Note: g mean enabled. d means disabled ] Current message level: 0x00000001 (1) Link detected: yes
If Supports Wake-on is g, then the support for wol feature is enabled on the NIC card.
Enabling wol option on the Ethernet Card
By default the Wake-on will be set to g in most of the machines. If not, use ethtool to set the g flag to the wol option of the NIC card as shown below.
# ethtool -s eth0 wol g
Note: You should execute ethtool as root, else you may get following error message.
$ /sbin/ethtool eth0 Settings for eth0: Cannot get device settings: Operation not permitted Cannot get wake-on-lan settings: Operation not permitted Current message level: 0x000000ff (255) Cannot get link status: Operation not permitted
Install wakeonlan package on a different machine
Install the wakeonlan package in the machine from where you need to send the magic packet to switch on your server.
# apt-get install wakeonlan
Note down the MAC address of the remote server
Note down the MAC address of the server that you wish to switch on remotely.
# ifconfig
eth0 Link encap:Ethernet HWaddr 00:16:k5:64:A9:68 [ Mac address ]
inet addr:192.168.6.56 Bcast:192.168.6.255 Mask:255.255.255.0
inet6 addr: fe80::216:17ff:fe6b:289/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:3179855 errors:0 dropped:0 overruns:0 frame:0
TX packets:2170162 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:3832534893 (3.5 GB) TX bytes:390304845 (372.2 MB)
Interrupt:17
Finally, Switch ON the machine remotely without physical access
When the server is not up, execute the following command from another machine which is connected to the same LAN. Once the magic packet is sent, the remote system will start to boot.
# wakeonlan 00:16:k5:64:A9:68
This article was written by SathiyaMoorthy, developer of enterprise postgres query analyser, an efficient tool for parsing postgresql log to generate html report, which can be used for fine tuning the postgres settings, and sql queries. The Geek Stuff welcomes your tips and guest articles.
Comments on this entry are closed.
I set Wake-on to ‘g’ using ethtool, and I’m able to shutdown and subsequently wake the machine using wakeonlan, but then the Wake-on flag is reset to ‘d’. I have to reset the flag to ‘g’ manually every time I reboot the machine.
Any ideas on how to get it to retain the ‘g’ setting?
Thanks,
Matt
Depends on distro.
According to this thread (it’s czech, but you can surely recognize the commands and filenames): http://www.abclinuxu.cz/poradna/linux/show/123114
In Debian I added this line to my /etc/network/interfaces:
post-up /usr/sbin/ethtool -s $IFACE wol g
And edited /etc/init.d/halt script not to turn off interfaces.
In my Gentoo I would probably do quite a similar thing in /etc/init.d/net.eth0 in postup() function.
But I still do sth wrong and computer still doesn’t react when I run wol or wakeonline (tried both for sure) even when i’m directly connected via ethernet cable. =( Probably the network card is not listenning at all. I would be thankfull for any hints.
I just created 2 scripts, one for suspend and one for shutdown that runs
“ethtool -s eth0 wol g”
before issuing the shutdown or suspend command.
Matt
Nice article – works like a charm 🙂
Thanks, Yakup_M
Nice information friends,
it helped alot.
That is great. Worked perfectly.
I will say that you could move the reminder to query ethtool while root higher in the article. When running your first command, ethtool reported wake on lan was not supported. I happened to keep reading and then retried with root to see it was supported.
Thanks.
Thank you for this article! I’ve been setting up a Ubuntu web server on my LAN this weekend, and this was the finishing touches for my setup! Now I don’t even have to turn it on manually 🙂
I already run the shutdown command remotely on the server , then how to get the MAC ADDRESS of the server.
you can always check to see if there is a entry in DNS for the machine that is turned off on your router / DNS server for the machine and get the MAC from there. If it has been turned off for a long time there is a chance the record has been purged from DNS.
not able to set wake online on centos machine
[root@delhi40 ~]# ethtool -s ens7f0 wol g
Cannot set new wake-on-lan settings: Operation not supported
not setting wol
[root@delhi40 ~]# uname -a
Linux delhi40.bol.net.in 3.10.0-123.el7.x86_64 #1 SMP Mon Jun 30 12:09:22 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux
[root@delhi40 ~]#