📜 ⬆️ ⬇️

Turning on the server using a mobile phone from the outside world

image Good day habravchane! It all started with the fact that working remotely in the terminal it was necessary to restart the server. Toli did not ask the day, thoughts were toli about something else and instead of the command:
sudo shutdown -r now
sent him to rest after a hard day at work, with the command:
sudo shutdown now Enter
And everything happened mechanically and so quickly that even he did not have time to understand. Understanding began to arrive in 15-20 minutes, after uncontrolled attempts to connect remotely to the terminal. And I think it is not even worth talking about how far the server was, and it was almost impossible to reach it. After long telephone conversations and explanations where to go, and where to press, the server still returned to the working rhythm. After that, the idea of ​​turning on the server remotely appeared.

And so we have:

a . enable / check server WOL support
b . enable / check WOL support in Ubuntu Server
To do this, install the package ethtool
sudo apt-get install ethtool
after which we check WOL support
sudo ethtool <> | grep Wake
command output should be as follows
Supports Wake-on: g
Wake-on: g
This suggests that the network card supports WOL and it is enabled. If
Supports Wake-on:
a letter other than g , the network card does not support WOL. And if it is off
Wake-on: d
then enable it with the following command:
sudo ethtool -s <> wol g
On many systems, this command has to be executed after a reboot, so we’ll make it run every time when the system boots automatically. To do this, create the wakeonlan.conf file with the following commands:
 sudo bash -c "cat > /etc/init/wakeonlan.conf" <<'EOF' start on started network script for interface in $(cut -d: -f1 /proc/net/dev | tail -n +3); do logger -t 'wakeonlan init script' enabling wake on lan for $interface ethtool -s $interface wol g done end script 

Make the file executable
sudo chmod +x /etc/init/wakeonlan.conf
and run the service
sudo service wakeonlan start
c . on the Cisco router, configure the WOL packet forwarding. To do this, add the following commands:
interface X
ip directed-broadcast
!
!
ip nat inside source static udp abc255 7 interface Y 7
Where
interface X - local interface (ip nat inside)
interface Y - external interface (ip nat outside)
d . On the Nokia N9, add the perl script that creates the WOL package with the following content:
wol.pl
 #!/usr/bin/perl -w # wol.pl, written 20031220 by Walter Roberson robe...@ibd.nrc-cnrc.gc.ca # this program constructs a WOL (Wake on Lan) packet suitable for # sending locally or over a net. The MAC of the system to be woken # is required. # # The IP address the user supplies should NOT be # the IP address of the system to be woken: instead it should be the # subnet directed broadcast IP (eg, 192.168.1.255) of any subnet # known to be present on the segment of the target system. This # would usually be the directed broadcast IP of the target system itself, # but need not be in cases of multiple subnets that aren't carefully # VLAN'd away from each other. # # To repeat: do NOT use the IP address of the target system. Not unless # you are on the same subnet and you are using a static ARP entry. # The target system is asleep, so it isn't going to answer an ARP # from a router trying to find that particular address. Use a # broadcast address, or some other packet forwarding trick. use strict; require 5.002; use Socket; use Sys::Hostname; my ( $hisiaddr, $hispaddr, $hisMACtext, $hisaddr, $hisport, $proto, @MACbytes, $hisMACbin, $magicbody ); die "Syntax: $0 MAC ipaddr [port]" if @ARGV < 2; $hisMACtext = shift @ARGV; $hisaddr = shift @ARGV; $hisport = shift @ARGV || 22357; # default 'WU', no significance $magicbody = "\xff" x 6; @MACbytes = split /[:-]/, $hisMACtext; die "MAC wrong size" unless @MACbytes == 6; $hisMACbin = pack "H*H*H*H*H*H*", @MACbytes; $magicbody .= $hisMACbin x 16; $proto = getprotobyname('udp'); socket(SOCKET, PF_INET, SOCK_DGRAM, $proto) || die "socket: $!"; $| = 1; print "WOL packet being sent to udp port $hisport of ip $hisaddr\n"; $hisiaddr = inet_aton($hisaddr) || die "unknown host $hisaddr"; $hispaddr = sockaddr_in($hisport, $hisiaddr); defined(send(SOCKET, $magicbody, 0, $hispaddr)) || die "send $hisaddr: $!"; 

make the script executable in the phone terminal
chmod +x wol.pl
the script is run in the terminal with the following parameters
./wol.pl <MAC XX-XX-XX-XX-XX-XX> < IP > < udp ( 7)>

The most surprising thing is that from the moment of that ridiculous mistake, I never had to use it, except perhaps only during the test set-up.

References:

')

Source: https://habr.com/ru/post/184950/


All Articles