Your DynDNS on the knee

So let's say you are a web developer. Suppose you have a Linux home computer running 24x7 and a dynamic external ip. Suppose you need to connect to it via ssh or show web projects to the customer that for some reason cannot be laid out for hosting for a long time or even at all (just because of the need to show VPN to third parties is not an option). Let's say you are not satisfied with DynDNS services. Let's get started.

I agree, the conditions are specific - but what doesn’t happen in life.

The scheme is approximately the same - a home PC is knocking on your site (you are a web developer after all, you should have a site), that fixes the IP address and gives it to you.

First, configure the output (actually the input) of the home PC (hereinafter referred to as the server, for simplicity) to the external network. If your PC looks at the Internet directly, feel free to skip this point. This is something like the setup through the web interface of my ASUS WL-520GU router with the alternative tomatoUSB firmware - I open port 666 for ssh forwarding on the router and port 667 for redirecting web requests to the server (internal address is 192.168.1.100, the IP address is fixed to the server by the rules DHCP of the same router).



Some routers need to be rebooted, but with a high degree of probability they themselves will report this.

It remains to configure the server to query on the cron of the page on your hosting (http://my.site/testippage.php, for example).

In console -
crontab -e
*/5 * * * * wget http://my.site/testippage.php?key=habrahabr -O /dev/null

(every 5 minutes we download the page my.site/testippage.php to nowhere)

The key transmitted by the get request serves as a small protection against accidental or intentional sabotage.

Now configure the server side. I used to use the MySQL database to store the current ip address - but this is completely unnecessary, and in the process of editing the article I got the following code:


As you can see from the code, if the get parameter is passed to the script, it records the ip of the knocker, if the page parameter redirects to your home computer, and if nothing comes to it, it simply displays the ip address.

To show the customer the project in the project folder of the server - you need to give him the link my.site/testippage.php?page=project .

Now the last part is to configure the laptop to connect to the server with one command. Let's make a script, say homeslackconnect.sh:
content=$(wget http://my.site/testippage.php -q -O -)
ssh $content -p 666 -l niph

it reads the ip address into the content variable and tries to connect to the received address through port 666 as the niph user. Which was originally required.

I do not argue that DynDNS is a much simpler solution, but not all routers can use free DynDNS servers, moreover, they tend to become not so free, and their solution is always warmer. Ask questions in the comments, I hope someone this decision will help simplify your life.

Also popular now: