How to Start Your Pc via Lan or Wan

Oppression
  11 years ago
  8

Before you do anything you will need to know if your Ethernet card supports the ability to wake up your pc. To find this out install this tool:

 sudo aptitude install ethtool

then give this command

 sudo ethtool eth0

the result of this command must be something like this

 Supported ports: [ MII ]
Supported link modes:   10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/Full
Supports auto-negotiation: Yes
Advertised link modes:  10baseT/Half 10baseT/Full
100baseT/Half 100baseT/Full
1000baseT/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

We are interested in the line that says  “Supports Wake-on: g” if the end of the line is “g” that means it is support to wake up your pc if it is “d” then you will probably need to buy a new one.

The second step is to declare a static ip to your pc, that is easy you need to edit the

 sudo nano /etc/network/interfaces

or of you use a graphic environment go to network-manager  and add a static ip if you need more information how to do this is easy to find information on the internet.

The third step is to make a small script on the

 sudo nano /usr/bin/wakewol

and add these lines

 #!/bin/bash
ethtool -s eth0 wol g

Save the file and use the sudo chmod 755 wakewol to make it executable, after that go to

 sudo nano /etc/network/interfaces

and at the end add this line

 post-down /usr/bin/wakewol

Save the above script and give the below command in orfer to see your mac address of your ethernet card – make sure to note the mac address. You will need a second computer to wake up the first one.

 ifconfig eth0 |grep HWaddr

OK now you turn off your first computer and at the second pc you will need to install this:

 sudo aptitude install wakeonlan

now execute this command with the mac address which you noted before

 wakeonlan 01:02:03:04:05:06

if you want to turn on your pc outside your lan network you will need to do some more steps. You will need to port forward the port 9 to your computer which you want to wake up. Because the setup of every router is different you must take a look here how to do that  http://portforward.com/

The last step is to declare a static ip and at your router. Otherwise after 30 min it will refresh ips and it will not know where to send the signal. to do that you need to connect to your router via telnet in my case my router’s ip is 192.168.1.254

 telnet 192.168.1.254

give your username and password

 Trying 192.168.1.254...
Connected to 192.168.1.254.
Escape character is '^]'.
Username :username
Password : password

and write menu

 
┌─────────────────────────────────┤ menu ├──────────────────────────────────┐
│                                 └──────┘                                  │
│[firewall]     [service]      [autopvc]      [connection]   [cwmp]         │
│[dhcp]         [dns]          [dsd]          [dyndns]       [eth]          │
│[atm]          [config]       [debug]        [env]          [expr]         │
│[grp]          [hostmgr]      [ids]          [igmp]         [interface]    │
│[ip]           [ipqos]        [label]        [language]     [mbus]         │
│[memm]         [mlp]          [nat]          [ppp]          [pptp]         │
│[ra]           [script]       [snmp]         [sntp]         [software]     │
│[system]       [systemlog]    [tls]          [upgrade]      [upnp]         │
│[user]         [wireless]     [xdsl]                                       │
│                                                                           │
│                                                                           │
├───────────────────────────────────────────────────────────────────────────┤
│                <Ok>                                <Cancel>               │

you will see something like that,  choose “ip” and then “arplist” to see all  computer which are connect to your router. You shoud find your computer  has a dynamic ip, choose “arpdelete” to remove your computer’s ip and then “arpadd” to add it as in below example

 │intf = LocalNetwork
│ip  =    192.168.1.xxx
│[hwaddr]  =   01:02:03:04:05:06

That is it, now you if you have a smartphone you can install the wakeonlan app and  turn on your computer from anywhere. Finally you can  note your router’s external ip, or if you want you can use a DynamicDNS, in order to wake up your pc from outside your lan network.

Comments
sercancelik 9 years ago

What if router doesn't allow editing arp tables via telnet.
From the web interface, i declared a static ip with my mac address and forwarded port 9 to that ip.
After this waking up fron lan is ok but i still can't wake up from wan.
I can access to web server on my pc when it is running via port 80 and acces to my modem & router's web interface via port 8080 but can't wake the pc up.
I am using a dynamic dns address for updating wan ip and trying to wake up pc with same address either the way entering wan ip exactly doesn't matters.


entropy 9 years ago

Thank you! This worked very well. A couple of observations:

1) If you get "Wake-on: d" from ethtool you don't necessarily need a new ethernet card; you might just need to turn on Wake-on-LAN in the BIOS.

2) Your network might not use the default wakeonlan broadcast address (255.255.255.255). You can find yours with:

ifconfig |grep Bcast

Then use it with wakeonlan like this:
wakeonlan -i [Bcast IP] [MAC address]


joz13 10 years ago

TYPO!
sudo -y apt-get install zenity, the -y option should come after apt-get. we dont want to pass 'yes' to sudo!


joz13 10 years ago

Good and clear tutorial thank you! Saves me from running down stairs all the time :) I wrote a little "add-on" to you're tutorial to provide a easy way to execute the script (scripts in general) from the application menu, almost like it's a GUI application.

We can do that in the following manner. Open a terminal window and execute the following command. Use Gedit, not Kate, in the command if you use a Gnome/GTK desktop.


mkdir ~/.scripts && touch ~/.scripts/wake-pc.sh && kate ~/.scripts/wake-pc.sh


Copy/paste the information from below in the new file and replace the mac and ip value's from those corresponding on you're machine.

__

#!/bin/bash
ip=255.255.255.255
mac=00:00:00:00:00:00

if ping -c 1 -t 1 $ip > /dev/null; then
kdialog --msgbox "Pc is already running"
else
/usr/bin/wakeonlan $mac
kdialog --msgbox "Starting $ip"
fi
done
__


If you run a GTK desktop, install zenity from the terminal with the following command and replace the kdialog lines with 'zenity --info --text="Whatever you want to say!"'.


sudo -y apt-get install zenity


Then make the script executable via properties/permissions in a GUI ore execute this command.


chmod u+x ~/.scripts/wake-pc.sh


Now we make a .desktop file to add end execute the script from you're local application menu. We make a new file in you're ~/.local/share/applications/ folder and name it wake-pc.desktop. Run this command from the terminal to do so. Again, use Gedit if you use GTK!


touch ~/.local/share/applications/wake-pc.desktop && kate ~/.local/share/applications/wake-pc.desktop


Copy and paste these entries in the just opened file. After saving and closing you should find you're script in the application menu under Applications->Utilities.

[Desktop Entry]
Name=wake-pc
GenericName=wake-pc
Comment=Wakeup a remote pc.
Exec=/bin/bash /home/$USER/.scripts/wake-pc.sh
TryExec=/bin/bash
Icon=user-away
StartupNotify=true
Terminal=false
Type=Application
Categories=Utility;wake-pc
Keywords=wol;wake;wakeup;wake-up;remote;startup;boot;lan;client

Have fun waking you're remote machine!

Joz.