Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Self hosted Dynamic DNS / No-IP script in PHP
* Simple Dynamic DNS / No-IP script for Route53
* Setup:
* 1) Setup a new Route53 zone to hold your dynamic DNS records (e.g.
* 2) Make sure this instance has permission to modify this Route53 zone (e.g. instance IAM profile, .aws credentials or ENV variables)
* 3) Upload this PHP script to your instance (make sure vendor files are availalbe by running: composer require aws/aws-sdk-php)
* 4) Put the allowed hostnames in the list below
* 5) Visit this PHP script in a browser from your desired location (e.g. office, home, parents house, friends house) to set the dynamic IP entry
* 6) Include the hostname in the URL like so:
* 7) Use the new DNS entry to access your services remotely (e.g. office VPN or home CCTV footage)
* Todo: make better
* Todo: auth
// Your Zone ID from Route53
$hosted_zone_id = 'ABCD12345BCDAF';
// Your Zone name from Route53
$hosted_zone_name = '';
// Allowed subdomains:
// e.g. allowing 'office' below will let you set ''
// visit to set the 'office' IP address.
$allowed_hostnames = array(
require 'vendor/autoload.php';
use Aws\Route53\Route53Client;
use Aws\Common\Credentials\Credentials;
if(isset($_GET['host']) && in_array($_GET['host'], $allowed_hostnames)){
$hostname = $_GET['host'] . '.' . $hosted_zone_name;
$ip_address = $_SERVER['REMOTE_ADDR'];
<form action="" method="post">
<input type="hidden" name="go" value="yes">
Please confirm you wish to change the IP address for this DNS entry: <br/>
<code><?php echo $hostname;?></code> <br/>
to this new IP address: <code><?php echo $ip_address;?></code>
<input type="submit" name="yes" value="Confirm">
$client = new Aws\Route53\Route53Client([
'version' => 'latest',
'region' => 'us-east-1',
$result = $client->changeResourceRecordSets(array(
'HostedZoneId' => $hosted_zone_id,
'ChangeBatch' => array(
'Comment' => 'string',
'Changes' => array(
'Action' => 'UPSERT',
'ResourceRecordSet' => array(
'Name' => $hostname,
'Type' => 'A',
'TTL' => 600,
'ResourceRecords' => array(
'Value' => $ip_address,
echo "Sweet. <code>$hostname</code> should resolve to IP <code>$ip_address</code> shortly.";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment