Tuesday, March 29, 2011

Set up Wake on LAN under Ubuntu


Perform the following on the PC you wish to wake:
  1. turn on Wake on Lan, or WOL, in the PC's BIOS.  How to do this will vary widely depending on your PC so you will need to research this one yourself

  2. Get the device id of the Ethernet adapter on which you wish to enable Wake on LAN.

    Open a Terminal' and type ifconfig.  The device id will appear next to a block of text that mentions Ethernet. in the response below eth0 is the Ethernet adapter

    eth0      Link encap:Ethernet  HWaddr 01:23:45:67:89:ab
              inet addr:192.168.1.2  Bcast:192.168.1.255  Mask:255.255.255.0
              inet6 addr: fe80::215:f2ff:fe6f:3487/64 Scope:Link
              UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
              RX packets:71495 errors:0 dropped:0 overruns:0 frame:0
              TX packets:76190 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:1000
              RX bytes:23164212 (22.0 MiB)  TX bytes:7625016 (7.2 MiB)
              Interrupt:217 Base address:0xd400
    
    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:1290 errors:0 dropped:0 overruns:0 frame:0
              TX packets:1290 errors:0 dropped:0 overruns:0 carrier:0
              collisions:0 txqueuelen:0
              RX bytes:161182 (157.4 KiB)  TX bytes:161182 (157.4 KiB)

  3. Create a file under /etc/init.d/. This file is going to hook into your PC's boot processes and enable WOL each time your PC is booted. You may give this file whatever name you like.

  4. Inside the file add the code below.  Insert the ID of your Ethernet adapter in place of {adapter Id}.

    #!/bin/bash
    ethtool -s {adapter id} wol g
    exit

  5. Set appropriate permissions on your script file with the command below.  Change {script file} to the name of the script file you created above.

     sudo chmod a+x {script file}

  6. Ensure the script runs at start up with the following command

    update-rc.d -f {script file} defaults

Perform the following on the Wakee

To wake the pc you enabled WOL on above, follow the steps below:

  1. Get the mac address of the PC you wish to wake with the following command.  (obviously you will need to do this on the target PC):

    ifconfig | grep HW
  2. Wake the target PC with the following command:

    wakeonlan {mac address of the pc you are waking}

No comments:

Post a Comment