Get a domain using GCP and MyDNS (NAT traversal Wake on LAN [1])

Introduction

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".

ezgif-6-a3bc222e322b.gif

-[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.

Purpose

The purpose is simple and I just want to start my home desktop PC with Wake on LAN (WOL) from the outside like this.

object.png

problem

--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.

solution

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 network_detail.png

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

Mainly used

--Service - Google Cloud Platform - Softether - MyDNS - mod_wsgi - apache - LINE bot

Get a domain using GCP and MyDNS

I will write it step by step as a memorandum. To achieve the above, first "get a domain using GCP and MyDNS".

GCP

Creating a VM instance

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.

gcp1.png

Organization is absent.

gcp2.png

After creating the project, create a VM instance.

gcp3.png

After creating it earlier, select the project.

gcp4.png gcp5.png

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.

gcp7.png

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.

gcp6.png

** * Important ** Enable IP forwarding. This cannot be changed later!

gcp8.png gcp9.png

After that, click "Create" to complete the creation of the VM instance.

Install GCloud

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

Check if SSH connection is possible from gcloud

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}"

Firewall settings for SSH

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.

ssh3.png ssh4.png

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}"

Time setting

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

Setting

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.

mydns1.png

Next, set DDNS from IP ADDR DIRECT. Return to the GCP site

dnsupdate1.png

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.

mydns2.png

IP notification

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

dnsupdate1.png

In EDIT> custom metadata, enter the following in the red square below.

#! /bin/bash
bash /home/{name}/vpn/update_ip.sh
dnsupdate2.png

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.

in conclusion

For the time being, it's long, so it ends here.

reference

Start from now on GCP (GCE) Safely use the free tier

Recommended Posts

Get a domain using GCP and MyDNS (NAT traversal Wake on LAN [1])
Create a Python script for Wake on LAN (NAT traversal Wake on LAN [5])
Reverse proxy from Apache on GCP to local Raspberry Pi Apache (NAT traversal Wake on LAN [3])
Set up Softether Server on GCP (Connect from iPhone / Raspberry Pi) (NAT traversal Wake on LAN [2])
Turn Raspberry Pi into a router (Wake on LAN [4] over NAT)
Wake on lan on Linux
Building a Python environment on a Mac and using Jupyter lab
Build a Chainer environment using CUDA and cuDNN on a p2 instance
Build a game leaderboard on Alibaba cloud using Python and Redis
Get data from MySQL on a VPS with Python 3 and SQLAlchemy
Get data from your website on a regular basis using ScraperWiki