self-construction - DynDNS-Alternative

Raspberry Pi as WLAN Server

If you already have your own webserver/webspace on the Internet and some programming knowledge, you can save yourself a service like DynDNS.org & Co. without much effort if you want to access parts of your home network from the road. Such services provide a host name/URL (e.g. my-home-network.dyndns.org) which is then forwarded to the IP address of the home network. In addition to a user account, which is often subject to a fee, you then only have to configure your router at home so that it automatically transmits this to the DynDNS service in the event of an IP change.

Today, many Internet connections at home already have more or less fixed IP addresses, at least as long as the cable modem, for example, is not disconnected from the power supply for a short time. So if you want to be safe again, you can set up a DynDNS solution or build on the fast one yourself.

Table of contents:

Create your own DynDNS-Service

1.) Write a PHP script that receives, stores and outputs the new IP address of the home network.
2.) Install the PHP script on a webserver/webspace that is publicly accessible. (for example http://tinkering-sascha.com/my_dyndns/index.php)
3.) Configure your home server (e.g. Raspberry Pi Raspberry Pi)  (for example Cronjob or Task-Scheduler), so the PHP-Script is called periodically to tell the new IP-Address.

Step 1 and 2 - PHP Scripting

To keep the whole thing as simple as possible, I did it without a database connection. So the IP address of the home network is simply written into a file.

/*  filename -> maybe change it.; config_file which will receive the IP-Address of the home network; */
$config_file = "myip.txt";

To add a touch of security to the script, we next define two variables, each with a random string. These strings must be transmitted when writing ($secret) and reading ($getip) the IP address of the home network home network to ensure that only authorized people have access to the functionality. If this is not enough, you can encrypt the connection via SSL and build a login system around it. 😉

//This string is passed by the home network server via GET, whereupon the new IP address is stored in the config-file.;
$secret = "1234567890";

//This string must be passed by GET to get the current IP address of the home network;
$getip = "0987654321";

Now a few lines of code will follow to write, read and output the IP address.

if (isset($_GET['secret']))
{
if (strcmp($secret, $_GET['secret']) == 0)
{
//secret korrekt; IP-Adresse speichern;
$ip = $_SERVER['REMOTE_ADDR'];

$f = fopen($config_file, "w");
fwrite($f, $ip);
fclose($f);
}
}
else if (isset($_GET['getip']))
{
if (strcmp($getip, $_GET['getip']) == 0)
{
//secret korrekt; IP-Adresse herausgeben;
$f = fopen($config_file, "r");
$ip = fread($f, 32);
fclose($f);

echo $ip;
}
}

The script is now ready for a test, so upload it. If you call the URL of the web space where the script is located with the parameter secret=1234567890, the IP address of the calling computer is stored. A call with getip=0987654321 on the other hand returns the IP address.

kraken.jpg

Depending on how you want to use the access to the home network, it might make sense to use the header ("Location: http://".$ip."/deeplink-ins-heimnetz/") to forward the user or the calling computer directly instead of displaying the IP address with echo. If you only want to retrieve the IP address instead, e.g. via an app, in order to create your own paths or calls into the network, the echo of the IP address is sufficient at this point.

Link to the PHP-Script that contains the code for your own DynDNS-Server:
-= Download DynDNS-Server =-

Step 3 - Call PHP script from home network

In my case there is a Raspberry Pi (Model B) Raspberry Pi (Model B) in the home network, which acts as server. My webrouter has been configured (IP forwarding) so that the RaspberryPi responds to requests from the Internet on port 80 (http). To get the Pi to do this, let's say every 10 minutes we call the PHP script to tell us the new IP address of the home network, open the /etc/crontab file and add the following line:

*/10 * * * * pi wget -O /dev/null "http://my-webspace.de/index.php?secret=1234567890"

Now the Pi passes the IP address of the home network at 10-minute intervals. - Simple solution! 🙂

Conclusion - Build your own DynDNS

Of course this is not a professional solution, but it is a simple and easy solution to realize your own DynDNS service. All in all, it does what it should do! 🙂

kraken l.jpg

As already briefly mentioned, the script has to be adapted with regard to security and data protection. In any case, strong passwords ($secret and $getip) and a random name of at least 16 characters for the file in which the IP address of the home network is stored would make sense. ($config_file -> e.g. jkSD43jkdmrwf4993jk_43s4AA!.txt).

SSL encryption wouldn't be bad either, but the security issue is relative in this case, at least as far as reading the IP address is concerned. Because every service running in the home network and which should be accessible from outside, be it cloud or media/web server, should have its own access control or login with user name and password, so that it is not too tragic if someone gets to the IP address of the home network, so that the IP address could also be displayed without the $getip parameter when calling the script. So it's simply up to you to decide how much effort you want to put into the protection....

Author: Sascha from Tinkering-Sascha.com

Author: Sascha

Some words about myself. My name is Sascha - i'm a software developer and martial artist from germany. Besides programming and martial arts some of my interests and hobbies are cooking, fitness and hearing loud heavy metal music. :D

This might also be interesting for you

Experiment: Hacking Ethereum Wallets - Bruteforce

Some time ago I came across a YouTube video by chance with the title: "Eth Wallet Bruteforce Hack". A programmer showed a simple Python script which could generate a random private key (64 characters / 32 bytes / 256 bits). This was used to calculate the public-key and address and pass it to a blockchain … Continue reading "Experiment: Hacking Ethereum Wallets - Bruteforce"


pi_robot - Playing with Raspberry Pi, iPad and some Code

The Raspberry Pi is still one of the most popular mini computers, not only among hobbyists. Cost-effective (about 30 to 40,- EUR depending on the model), flexible in the field of application and at the latest since the equipped with enough CPU power and memory to solve even more complex tasks. With the 1.2 GHz … Continue reading "pi_robot - Playing with Raspberry Pi, iPad and some Code"


Flashing firmware - ESP8266-WiFi-Module

Since I recently started to deal more intensively with the topics "Smart Home" and "Home automation" I decided to publish some of my construction sites, stumbling blocks and solutions here. As already mentioned in the article about my Smart-Home-Project V1 I use the WLAN module , because it is small, reliable and cheap. In this … Continue reading "Flashing firmware - ESP8266-WiFi-Module"


Smart Home V1 - Do it yourself

I've been planning my smart home for some time now. Besides the cost factor for all the great things I imagine, I often lack the necessary time for detailed planning and implementation. So I decided to start somewhere and write down this DIY project in parallel...let's see where it leads...I ask for your indulgence if … Continue reading "Smart Home V1 - Do it yourself"


Program your own Screen Recorder / Capture Software

While searching for an easy to use screen recorder tool, I stumbled across all kinds of free and paid software solutions. From my point of view, pretty much all of them were either completely overloaded, difficult or complicated to use. Others were just expensive in relation to the functionality. My conclusion: Program yourself! Table of … Continue reading "Program your own Screen Recorder / Capture Software"


Leave a Reply

Your email address will not be published. Required fields are marked *

I have read and accepted the privacy policy!