6

I have a Ubuntu server (16.10) at home and was wondering if there is a way to turn it on remotely when I am away from home?

I set up Wake-On-LAN but that only seems to work when I'm using another computer connected to the same network as my Ubuntu server.

Any ideas on getting WOL working remotely?

Mat
  • 51,578
  • 10
  • 158
  • 140
Jono
  • 181
  • 1
  • 6

3 Answers3

11

First, the fact that your computer is running Ubuntu when powered on is unrelated to Wake-on-LAN (WOL) functionality.

Second, WOL uses Ethernet frames with a particular format.

Third, Ethernet frames are not routed outside of the local network segment. In the case of the Internet, intermediate networks might not even use Ethernet at all.

The consequence of the second and third points is that, in order to send a WOL request to a computer on a network, you need to do so from another system on the local network segment. It is not possible to directly issue WOL requests over the Internet.

Of course, you can do something like what CyberFonic suggests and have a small, low-power system on the local network segment that you can use to issue a WOL request. But in that case, the WOL request is really issued by another system on the local network segment; you just happen to access that system over the Internet.

user
  • 28,161
  • 13
  • 75
  • 138
  • 2
    Some home routers have WOL functionality, either by adding a WOL if a request is done to a specific machine, or with some other way (API or web-interface to router, note: independent to admin interface) – Giacomo Catenazzi Apr 04 '17 at 12:54
  • Can a router have WOL? that would be ideal as thats always on and low powered – Jono Apr 04 '17 at 13:17
  • 1
    @jonneymendoza: yes. Whether the capability is present on a stock off-the-shelf router is another question, but usually you can flash a third-party image and go back to stock without issues. Did it all the time with my WRT-54GLs and my current E4200, running DD-WRT, a third-party firmware for Linksys and other routers. Here, for example, is the DD-WRT walkthrough for WOL: http://www.dd-wrt.com/wiki/index.php/WOL – flith Apr 04 '17 at 13:21
  • "home routers [with] WOL functionality" is a subset of "another system on the local network segment with WOL functionality". – user Apr 04 '17 at 13:24
  • the use of Ubuntu is important. Under Windows that feature of my networking card was turned off by default. – Ciprian Tomoiagă Apr 04 '17 at 13:47
  • I thought the WOL protocol was designed such that the WOL packet could be embedded inside e.g. a UDP packet, so if you have your router forward a UDP port to the destination MAC, it will work. – Random832 Apr 04 '17 at 16:18
  • @Random832 the frame isn't sent "to" the target MAC, it's sent as a broadcast frame, and the target MAC is part of the payload. No sensible router is going to forward an incoming packet to broadcast. – hobbs Apr 04 '17 at 18:04
8

I'm in a similar situation to you. Using Ubuntu 16.04 LTS as a web server.

The server and a Raspberry Pi are both connected to the router via ethernet cable.

The RPi is running continuously. I have installed and configured fail2ban for extra security. The router is configured to allow SSH access from the internet to the RPi. When I want to start my power hungry IBM server. I SSH connect (mosh actually) to the RPi and run the following Python program:

""" Send a WoL packet to the specified MAC address
    NB: Won't work on OS/X.  The AF_PACKET is specific to Linux.
        Needs to be run with sudo.
"""
import socket

PREAMBLE = bytearray((0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF))

# Need to configure the following for the correct MAC of the target
MAC = bytearray((0x00, 0x14, 0x85, 0xa1, 0x43, 0xde))

pkt = PREAMBLE + 16*MAC
sock = socket.socket(socket.AF_PACKET, socket.SOCK_RAW)

# Configure the correct interface name
sock.bind(('enp2s1', 0))

sock.sendall(pkt)
sock.close()

If you don't have a static IP address, then you probably need to configure dynDNS or something similar and your domain addresses.

CyberFonic
  • 291
  • 2
  • 4
  • 3
    Also `apt-get install wakeonlan` – roaima Apr 04 '17 at 09:47
  • I think i will go with this route and buy myself a raspberry pi. which one do you have as they have a standard version and a Zero version? – Jono Apr 05 '17 at 08:42
  • I used a first gen. Model B. You need eNet - so the Zero wouldn't be suitable. – CyberFonic Apr 05 '17 at 10:35
  • which OS did u use? – Jono Apr 09 '17 at 13:42
  • Just standard Raspbian. I prefer Debian based OS since I'm comfortable using APT. But you could use any OS that supports CPython and Unix style AF_PACKET. Check the Python docs for more details on socket module. – CyberFonic Apr 11 '17 at 04:46
  • ok cool thanks. so if i save the below python script and save it inside the rasbperry pie. all i need to do is SSH into it and run the script? How do i run the script if the script is for example names turnOnServer.py – Jono Apr 12 '17 at 18:28
  • Hi i tried running your script with my mac address and got this error: sudo ./turnOnServerCommand.py ./turnOnServerCommand.py: 4: ./turnOnServerCommand.py: Send a WoL packet to the specified MAC address NB: Won't work on OS/X. The AF_PACKET is specific to Linux. Needs to be run with sudo. : not found – Jono Apr 12 '17 at 18:51
  • The error messages says it all. You need to run on Linux/Unix/BSD. Weren't you going to use a Raspberry Pi? BTW since you are accessing hardware, you do need to run such commands with sudo. – CyberFonic Apr 14 '17 at 01:56
  • i managed to fix that issue but now it says 'no such device' socket.error?? i added the correct ethernet interface name of the server pc i am trying to turn on on socket.bind but its saying it cant find it? – Jono Apr 18 '17 at 21:03
  • The device name for the socket.bind call is the device name on the machine sending the WoL packet, i.e. the RPi. The server is identified by the MAC. Please read the Wikipedia entry for WoL (see @mckenzm comments) to better understand what is going on. SO is not the place for detailed debugging assistance. – CyberFonic Apr 19 '17 at 23:06
-1

For WOL you could use port forwarding to another device on your network, various media players have this feature as a web accessible option.

You can also try wake on ring, or an IP powerboard after rigging bios to boot when AC power is applied. There are a number of Android/iOS apps that drive proprietary power points for this.

If it is a major brand server, there may be an out of band option (extra Ethernet port and daughterboard) you can purchase and fit. Higher end KVM over IP may support remote boot. There are a few options.

To clarify this, for a number of years I have been using an IP-Power 9258 powerboards, and these are useful, although I have not always been happy. They can be controlled with curl(1) (from script or a PHP dashboard). To get to it you are going to have to RDP/VNC in to an always-on workstation (lattepanda, say), run a low spec box webserver(Pi) on port 8081 say, or connect via VPN client. If you go this way, you need to be able to deal with or suppress grub hanging (waiting for keyboard) after an "incident". But it has the advantage of being able to cycle the power if everything else has failed. It is very common to go behind NAT to get things done.

mckenzm
  • 317
  • 2
  • 9
  • 1
    _Can_ you port-forward WOL packets? – roaima Apr 04 '17 at 08:46
  • 2
    @roaima No, because WOL frames are not TCP or UDP so have no concept of ports. – user Apr 04 '17 at 09:25
  • @MichaelKjörling that's what I'd thought, but the first part of this answer threw me. – roaima Apr 04 '17 at 09:33
  • You are not port forwarding the WOL packets, you are port forwarding to the server on the device that will send the WOL packets. You need that device to be always on. – mckenzm Apr 05 '17 at 05:35
  • If you read the specs, any UDP or TCP packet could be used as long as it has the critical WoL payload, see https://en.wikipedia.org/wiki/Wake-on-LAN. So if your router can be configured to port-forward to a specific MAC then it should (in theory) work. – CyberFonic Apr 11 '17 at 04:48
  • I really meant browsing to the webserver on a media player. Many of these have a form for sending WoL packets to custom MAC addresses so they can wake up the fileserver. Tedious but does the job. Thx for upvote. – mckenzm Apr 11 '17 at 20:11