Wake on LAN (is it the correct wording?) Beyond the NAT of the condominium, which has been a dream for many years, has finally been realized. Since it is quite long, I will write it separately. I will write it as a memorandum, but I hope any one will help you. This time, I will write about "Getting a domain using GCP and MyDNS".
-[1] Obtain a domain using GCP and MyDNS -[2] Set up Softether Server on GCP (Connect from iPhone / Raspberry Pi) -[3] Reverse proxy from Apache on GCP to local Raspberry Apache -[4] Make Raspberry Pi a router -[5] Create a Python script for Wake on LAN.
The purpose is simple and I just want to start my home desktop PC with Wake on LAN (WOL) from the outside like this.
--The port cannot be opened First of all, the port cannot be released due to the security of the condominium. Probably, as shown in the figure, the router is in the condominium, and unless you are the administrator, you can not set the port opening.
--Your own router does not support broadcasting Since there is only one LAN cable outlet in the condominium, I used the router I originally had in access point mode. However, the router did not support broadcasting. When sending a Magic Packet, it seems that it will not reach the desktop unless it is sent from the router to the broadcast.
I faced the above problem, but fortunately I had a Raspberry Pi at hand, so I was able to solve it by connecting as follows using this.
--Completion image of the network
In other words
--Turn Raspberry Pi into a router to send Magic Packets to broadcasts --Send Magic Packet with Python from Raspberry Pi --Use the cloud service Google cloud platform (GCP) so that you can access it from your smartphone outside --VPN connection between GCP and Raspberry Pi so that you can redirect from GCP to Raspberry Pi --Access GCP from LINE for ease of use
--Service - Google Cloud Platform - Softether - MyDNS - mod_wsgi - apache - LINE bot
I will write it step by step as a memorandum. To achieve the above, first "get a domain using GCP and MyDNS".
GCP
First, build a server using GCP. Refer to Official site GCP (GCE) to start from now on, safely use the free frame Create it.
First, create a project.
Organization is absent.
After creating the project, create a VM instance.
After creating it earlier, select the project.
For free, Region is the United States, and the machine type is a poor one. (Free frame) The part written later in the figure is the firewall setting. You can set it later, so you can leave it as it is.
For Boot Disk, I chose Ubuntu, which I'm used to. The capacity is free up to 30GB, so change it from the default value of 10GB.
** * Important ** Enable IP forwarding. This cannot be changed later!
After that, click "Create" to complete the creation of the VM instance.
Install gcloud
so that you can connect to the VM instance created by SSH.
mkdir ~/gcloud
cd ~/gcloud
Here Quick Start> Download the tar.gz
file according to your OS and put it in the directory you created earlier.
Then unzip the file as follows and install it.
tar xvzf gcloud.tar.gz
./google-cloud-sdk/install.sh
Restart the terminal and type the following command to complete the installation of gloud
.
gcloud init
After the installation is complete, link it with the GCP project you created earlier.
gcloud config set project {my-project or id}
Next, make an SSH connection to the VM instance.
gcloud compute ssh {instance name or id} #--ssh-flag="-p {port number}"
Set the firewall that was postponed. It seems better not to use the default port number. First, make an SSH connection to the VM instance and change the SSH settings.
gcloud compute ssh {instance name or id}
sudo cp -p /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
sudo sed -i -e "s/#Port 22/Port {port number}/g" /etc/ssh/sshd_config
sudo service ssh restart
After that, from the Web
Set the {port number}
set earlier in Compute Engine> VM Instances> View Network details as a rule.
It is OK if you can save and connect again with the following.
gcloud compute ssh {instance name or id} --ssh-flag="-p {port number}"
By default, it is not set to Japan time, so change it. Ssh connection,
sudo apt-get install dbus
sudo timedatectl set-timezone Asia/Tokyo
This completes the basic GCP settings. In addition, it is better to perform two-factor authentication for security, but I will omit it here.
DDNS
If you pay, you can get a fixed IP, but once you get the domain, use mydns to do DDNS. After creating an account with Join us> Sign UP from myDNS,
Set the domain from DOMAIN INFO> OK. CHECK> OK to complete.
Next, set DDNS from IP ADDR DIRECT. Return to the GCP site
As shown in the above figure, there is the current GCP External IP in the part hidden by the red square, so make a note of it and enter it. (Ignore the arrow) CHECK> OK to complete.
The IP will be notified when it is restarted and when it wakes up for 1 hour. First, SSH into GCP and create a shell script for the update.
mkdir ~/vpn
cd ~/vpn
vi update_ip.sh
update_ip.sh
#! /bin/bash
wget --http-user=mydnsxxxxx --http-password=~~~~~~~ http://www.mydns.jp/login.html -O /dev/null
Change the permissions.
chmod +x ~/vpn/update_ip.sh
Next, from the GCP site again
In EDIT> custom metadata, enter the following in the red square below.
#! /bin/bash
bash /home/{name}/vpn/update_ip.sh
This completes the notification settings when restarting.
Finally, just in case, set to notify every hour.
crontab -e
# update ip
* */1 * * * /home/{name}/vpn/update_ip.sh
This completes the DDNS settings.
For the time being, it's long, so it ends here.
Start from now on GCP (GCE) Safely use the free tier
Recommended Posts