Wake on LAN in Fedora Core
I've been researching the Wake on LAN protocol (the Wikipedia entry is very informative), in order to use it within my home network.
My #1 objective is to use it for my Fedora Core powered desktop:
- I often need to do some things remotely (ex: start a download, upload a file, change something in the config)
- I don't like leaving the computer on 24/7 and waste the precious resources of our planet
So naturally, Wake on LAN is the solution. Waking it up over the Internet is the second step of the problem (the solution depends on how the PC is connected to the Internet).
The problem with Fedora is that WOL doesn't work out of the box, at least that's the case on my PC. Everything is enabled in BIOS, so I was pretty sure that the machine is configured properly. Yet WOL did not work, so I assumed I had a problem with the Python script I wrote in order to send the magic packet.
The long story short, I was wrong. Wake on LAN was indeed disabled.
Here is what has to be done:
- ethtool eth1 (replace eth1 with whatever you are using)
- check the output, look for
Supports wake on: g
Wake-on: d - d stands for 'disabled', this is the current state of WOL; g stands for 'magic packet', it means that the NIC can be woken up by broadcasting a specially crafted packet.
- ethtool eth1 -s wol g (this will set WOL to g)
Now, you can shutdown the computer and try wake on LAN, you will see that it works.
However, it won't work next time you try it; weird, huh? If you run ethtool eth1 again you will see that the NIC has reverted to the initial setting.
It means that the setting must be changed each time the computer starts or when it is shut down, thus the setting we need becomes effective.
There are multiple ways to do that, I chose to edit /etc/rc.local by adding the line ethtool eth1 -s wol g to it. This will be executed each time the system starts, therefore the setting I need becomes effective.
Note: ethtool may not be installed on your system, so you should install it first. You should then see it here: /sbin/ethtool
Here is a Python script that implements Wake on LAN, by crafting a magicPacket and broadcasting it to UDP port 9. It should also work with Wake on LAN via the Internet, if you have a router that actually forwards such packets.
[code]
def WOL(MAC, routerIP):
targetPort = 9 #the PC I wish to wake
magicPacket=""
for i in range(6):
magicPacket+=chr(255)
splitMAC=MAC.split(':')
splitHexMAC=[]
for i in splitMAC:
splitHexMAC.append(int(i, 16))
for i in range(16):
for j in splitHexMAC:
magicPacket+=chr(j) #prior to this remove the separators
if routerIP==None:
routerIP="255.255.255.255"
print magicPacket, routerIP, targetPort, MAC
sockobj = socket(AF_INET, SOCK_DGRAM)
sockobj.connect((routerIP, targetPort))
try:
sockobj.send(magicPacket)
except:
print "could not send"
sockobj.close()
return
[/code]
Here is an example of calling this function
WOL("00:11:2F:A8:82:A6", "192.168.0.255")
The broadcast address can be changed to the IP of a router; provided that forwarding is set up correctly, it should work too.
nice! thank you. im realized it on wrt54gl + fc
email me some questions