How to redirect a url to a dynamic ip address but keep domain name in address bar? Dynamic DNS

2k views Asked by At

I am trying to create my own Dynamic DNS Server. I would like to remotely access my owncloud and apache webserver running on my RaspberryPi at home. My ipv4 is not public, but I have ipv6 setup and publicly accessible.

I have a cloud based host (rpi.myownddns.abc) - running apache - from which I am planning to run my Dynamic DNS Service. Till now I:

  1. created a myip.php page on rpi.myownddns.abc which stores my current ipv6 address in a text file (currentIP.text) on the webhost (my rpi has a bash script (ddns update client) which contacts myip.php with my eth0 ipv6 address every hour).

  2. created an index.php page on rpi.myownddns.abc which redirects me to the latest updated ipv6 address.

index.php

<?php
$myFile = "currentIP.txt";
$fh = fopen($myFile, 'r');
$theIP = fread($fh, filesize($myFile));
fclose($fh);
//echo $theIP;
header('Location: https://['.$theIP.']');
?>

Whenever I visit rpi.myownddns.abc I am redirected to my home server ipv6 as expected. However the URL looks something like https://[20a2:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx]/.

What I would like is to have my url show as rpi.myownddns.abc/owncloud for example, similar to what you get from ddns providers (ex noip). How do I achieve this?

I tried with apache mod_rewrite, but only managed to achieve the same redirect as with php. I checked into mod_alias, but this seems to require a domain name, and not an ip address.

Any help or pointers are appreciated. Thanks.

0

There are 0 answers