Turning on computers remotely
Posted by Steve on Wed 20 Apr 2005 at 08:42
To save power it's often useful to turn systems off, but of course when you do that you cannot use them! This is especially frustrating when you turn off a machine which is physically remote from you, but it doesn't need to be. Many modern PCs have the ability to be remotely "woken up" and turned on.
"WakeOnLan" is the term which is used for remotely powering on machines, as this is done by sending "magic network packets" to switch on machines.
To use wakeonlan you'll need either:
- A network card which supports WakeOnLan, which usually has a jumper which connects to your system's motherboard.
- An on-board network interface which supports this functionality.
Many modern systems with on-board NICs support wakeonlan, but it must be enabled in the BIOS. (Look for the option in the "power management" section of your BIOS, it might be called "wakeonlan", "netboot", or "wake on ring events").
If you have the requisite hardware support can see if it's enabled by your system by running the ethtool command, this shows whether the wakeonlan option is supported by your card, and whether it is enabled.
If you don't have this installed run:
apt-get install ethtool
Once it's installed run it with the name of your network interface:
root@lappy:~# ethtool eth0
Settings for eth0:
Supports Wake-on: g
Wake-on: d
Link detected: yes
Here we can see that wakeonlan support is available because of the g, but it's disabled. (This is explained in the manpage which you can read with "man ethtool"). To enable the magic packet support run:
root@lappy:~# ethtool -s eth0 wol g
Now you should be able to see that it's turned on:
root@lappy:~# ethtool eth0
Settings for eth0:
Supports Wake-on: g
Wake-on: g
Link detected: yes
Now that you know it's turned on you need to do one more thing. Wakeonlan software requires that you know the MAC address of the machine you wish to switch on, rather than the IP address.
To determine the MAC address you can either:
- Discover it on the machine itself before it is switched off, by using ifconfig
- Determine it remotely, whilst the machine is powered on and running.
To determine the MAC address via ifconfig just run it:
skx@mystery:~$ /sbin/ifconfig
eth0 Link encap:Ethernet HWaddr 00:0A:E6:F6:A3:F4
inet addr:192.168.1.80 Bcast:192.168.1.255 Mask:255.255.255.0
inet6 addr: fe80::20a:e6ff:fef6:a3f4/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:2218390 errors:0 dropped:0 overruns:0 frame:0
TX packets:3098440 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:1624008578 (1.5 GiB) TX bytes:1368310661 (1.2 GiB)
Interrupt:10 Base address:0xd400
Here the MAC address is 00:0A:E6:F6:A3:F4, it's on the first line and is described as the "HWaddr" or "hardware address".
If you're looking for the MAC address of another machine upon your LAN you can ping the machine, then look at the arp cache.
For example if I wished to determine the MAC address of the machine sun.my.flat from my current host I'd run the following two commands:
kx@mystery:~$ ping -c 1 sun PING sun.my.flat (192.168.1.1) 56(84) bytes of data. 64 bytes from sun (192.168.1.1): icmp_seq=1 ttl=64 time=0.202 ms --- sun.my.flat ping statistics --- 1 packets transmitted, 1 received, 0% packet loss, time 0ms rtt min/avg/max/mdev = 0.202/0.202/0.202/0.000 ms skx@mystery:~$ /usr/sbin/arp sun Address HWtype HWaddress Flags Mask Iface sun ether 08:00:20:C2:1E:F6 C eth0
The arp command shows the machine's MAC address, the ping being required first to make sure that my current machine knew the MAC address in the first place.
Once you have the MAC address you can shutdown the system you wish to test, and then attempt to restart it remotely.
There are several pieces of software for sending the wakeonlan packets inside the Debian archive:
- etherwake
- Requires root privileges and available in all Debian distributions.
- wakeonlan
- Can be used by all users, but only in the Sarge (testing) and unstable (Sid) repositories
I'm going to use wakeonlan, since it's already installed and can be used by non-root users:
skx@mystery:~$ wakeonlan 08:00:20:C2:1E:F6 Sending magic packet to 255.255.255.255:9 with 08:00:20:C2:1E:F6
This sends the magic wake on lan packet to the machine on the LAN with the hardware address "08:00:20:C2:1E:F6" which we previously determined belonged to the machine sun.
If all goes well the machine will begin to boot shortly after recieving the packet.
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
It's very hard to tell why it didn't work - did you perhaps try both of the software tools?
It might just be that the card is expecting something different from what is being sent.
Steve
-- Steve.org.uk
[ Parent | Reply to this comment ]
I also specified the ip address if the tool allowed.
*shrug*
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
Settings for eth0:
No data available
I get this message. What could be the problem?
My NIC is (onboard):
0000:02:05.0 Ethernet controller: 3Com Corporation 3c940 10/100/1000Base-T [Marvell] (rev 12)
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
That's strongly indicative of the fact you don't have WOL support, either that or it's not detected by your NIC's driver.
Steve
-- Steve.org.uk
[ Parent | Reply to this comment ]
The wake-on-lan feature works just fine when I shutdown windows (hibernate does not work with wol, but shutdown does). When I use the wakeonlan linux tool to power the machine on over network, it works.
But when I powerdown my machine in linux it does not work. I notice the LED on the back of my pc (nic) going off after shutdown in linux (while after shutdown in windows the LED stays on) and thus when I use the wakeonlan tool again, the pc wont respond. Probably because the nic is turned off by linux.
I also get the same message when using ethtool, that it cannot get data from the card. Maybe a driver problem? Ive build it into the kernel by the way, I dont realy like modules.
If anyone finds the solution to this problem, lightware@hotmail.com. thx.
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
Update: I upgraded to a gigabit switch, and Wake-on-LAN no longer works! I suspect it is a Marvell Yukon or an ASUS K8V-X issue. If the already shut down machine is disconnected from the 1000Mbps port and reconnected to a 100Mbps port, wakeup immediately works without any other change. Also, I tested that it is not a switch issue since the magic packet would go through any 1000Mbps links and get delivered as long as the NIC is in 100Mbps mode.
Not so awesome... Anyone encounter this strange problem?
[ Parent | Reply to this comment ]
My NIC is a Marvell 88E8001 controller on a Gigabyte GA-8IPE775 board. I am using Debian etch with kernel 2.6.18 and skge module.
After reading your post, I tried to set the interface-speed to 100Mbps on shutdown. Wake-on-Lan worked fine with that setting.
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
In my case, the fix had nothing to do with switching to 100Mbps at halt/shutdown. Just do it any time before sending the magic packet (i.e. using etherwake). Also make sure that autoneg is ON for both machined using "ethtool -s autoneg on".
First, I had to disable the if-down script from turning off the wake-on-lan interface on the target machine. I did this by editing /etc/init.d/networking and changing this line:
if ifdown -a --exclude=lo; then
to:
if ifdown -a --exclude=lo --exclude=eth0; then
Then I ran the following commands from the source machine:
ethtool -s eth2 speed 100 duplex half autoneg on
sleep 4
etherwake -i eth2 12:12:12:12:12:12
And BAM! It worked. I've waited for a while until the other machine is up-and-running then I switched back to using 1000Mb:
sleep 50
ethtool -s eth2 speed 1000 duplex full autoneg on
Thanks again!
[ Parent | Reply to this comment ]
I have a problem, I write :
ethtool -s eth0 wol g
and I have :
Supports Wake-on: g
Wake-on: g
Link detected: yes
but when I shutdown I can't wakeup computer
When I turn on computer normaly and write :
ethtool eth0
I get:
Supports Wake-on: g
Wake-on: d
Link detected: yes
Where is a problem ? Why it change from "Wake-on: g" into "Wake-on: d" after shutdown ? An why magic packet don't wakeup him ?
[ Parent | Reply to this comment ]
[ Send Message | View Steve's Scratchpad | View Weblogs ]
The ethtool setting must be run each time the machine boots, it is reset when the system brings the interface up.
If you can get it working you could create an init script to do it for you.
Why it's not working I don't know, perhaps the MAC address is wrong, the machine doesnt support it fully, or you need to try using a different software tool.
Steve
-- Steve.org.uk
[ Parent | Reply to this comment ]
iface eth0 inet dhcp
up ethertool -s eth0 wol=g
[ Parent | Reply to this comment ]
I edited /etc/init.d/networking and commented out the line
"ifdown -a --exclude=lo" and everything worked.
BTW the article mentions a little cable to connect nic and motherboard; on more recent PC's this is not necessary anmore (or even possible). The system works via PCI and the option in the BIOS might also be labeled "Wake on PCI".
[ Parent | Reply to this comment ]
up ethtool -s eth0 wol=g
[ Parent | Reply to this comment ]
up ethtool -s eth0 wol g
[ Parent | Reply to this comment ]
up ethtool -s $IFACE wol g
And then, if like me, your interface is eth2, it will actually work. Even if you change the interface name later.
[ Parent | Reply to this comment ]
while rebooting the network service says error
[ Parent | Reply to this comment ]
I don't want to brag, just wordering if you're, maybe, doing something wrong.
[ Parent | Reply to this comment ]
I couldn't make wakeonlan work on my local network attached to the eth1 interface.
etherwake -i eth1 did the job.
Everything works pretty much out of the box if you shut down Linux with poweroff etc. as you usually do. But if the ac power is lost while the machine is powered down waiting for wakeup, the wake up-call won't work anymore when the power is restored. The nic:s I guess sometimes seem to reset themselves and have to be set with ethtool again..
[ Parent | Reply to this comment ]
It displays status of each computer and maintains IP address, MAC address and user-defined computer name in SQL database. You are presented with list of compuetrs together with their status and link to turn on selected computers. You can input IP range to scan for new computers to add to database.
WoL packet is sent in UDP discard datagram, ping is done using UDP ping (because "ping" command has minimal timeout 1 second, which is too much when you have to ping 30 PCs).
It's not is release state, but I can send it to you if you want. Contact me on: marki /at/ onee /dot/ sk
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
I tried a few things with wakeonlan, but I did not succed. I guess the problem is in the subnetmask and the way to send it.
Thierry
[ Parent | Reply to this comment ]
open ( FILE, "/etc/dhcp3/dhcpd.conf" );
while ( ) {
($mac) = ($_ =~ /(([a-fA-F0-9]{2}:){5}[a-fA-F0-9]{2})/);
if ( $mac =~ /[a-fA-F0-9]{2}:/ ){
`etherwake -i eth1 $mac`;
}
}
close (FILE);
[ Parent | Reply to this comment ]
I plugged wol cable on ethernet card and motherboard, I set up BIOS so as to make it boot on wol signal (Wake on lan: enabled). When the machine is off, it doesn't boot on any magic packet sent to its interface.
I learned after googleling that my interface had to be set up to listen network and boot up the machine when it hears a magic packet. This should be done with ethtool command.
It looks pretty easy so far; but ethtool fails to set up wol on eth0, and it doesn't display any information about wol when typing "ethtool eth0". Again, google just says that my device simply doesn't supports this functionality.
But according to D-link technicians, it does; furthermore, I bought this card because it indeed supports it (OK, I should have bought a 3com ethernet card). One more element, Ubuntu edgy eft seems to be able to set up wol on this card, since ubuntu's ethtool tels about wol on this device; but I want pure Debian.
One more google session, and I suppose that instead of my device, this is its driver that doesn't support wake on lan. I also read that dlink driver doesn't support wol. By downloading dlink driver, I learned that it is sundance module. I can't compile it but this is not necessary, since it is already compiled, installed and loaded on my debian system. However, there is still no wol.
Maybe it is an option I should give to the kernel when booting, but I can't find any information on what eventual option I could give. Maybe I should recompile my kernel with correct options, which ones ?
I also read that I should install and use sk98lin driver instead of dlink's, but it is already installed, how do I do to setup Debian to make my d-link device to work with it instead of working with sundance ? Is it a good solution ?
Do you have an idea on what happens, on what I can/should do ?
[ Parent | Reply to this comment ]
It's work.
Now, i wanted to know if it is possible to shutdown a PC remotely.
Yes of course, with SSH.
But, i wanted to do that WITHOUT logging in,
for example : shutdown <MAC ADRESS>
Do you understand ?
Thanks
[ Parent | Reply to this comment ]
https://ool-43537bf6.dyn.optonline.net/Power%20Web%20Button.htm
[ Parent | Reply to this comment ]