Linode Forum
Linode Community Forums
 FAQFAQ    SearchSearch    MembersMembers      Register Register 
 LoginLogin [ Anonymous ] 
Post new topic  Reply to topic
Author Message
 Post subject: Custom dynamic DNS
PostPosted: Fri Aug 31, 2012 5:22 pm 
Offline
Senior Newbie

Joined: Wed Feb 24, 2010 2:08 pm
Posts: 16
Hi,

Anyone know how to create your own custom dynamic dns solution, like dyndns?

Any how tos would be good.


Top
   
 Post subject: Re: Custom dynamic DNS
PostPosted: Fri Aug 31, 2012 8:16 pm 
Offline
Senior Member
User avatar

Joined: Tue Apr 13, 2004 6:54 pm
Posts: 833
I created a child-domain "dyn"
dyn IN NS server1
dyn IN NS server2

The "dyn.mydomain.example"
Code:
$ORIGIN .
$TTL 5  ; 5 seconds
dyn.mydomain.example          IN SOA  localhost. root.localhost. (
                                1997022716 ; serial
                                60         ; refresh (1 minute)
                                60         ; retry (1 minute)
                                3600000    ; expire (5 weeks 6 days 16 hours)
                                10800      ; minimum (3 hours)
                                )
                        NS      server1
                        NS      server2

$ORIGIN dyn.mydomain.example
home                    A       1.2.3.4


So now "home.dyn.mydomain.example" is the DNS entry that I'll change.

In named.conf
Code:
zone "dyn.mydomain.example" {
        type master;
        file "src/dyn.mydomain.example";

        allow-update {127.0.0.1;};
};


This is weak security 'cos anyone on localhost would be able to update this domain, but since I'm the only one...

Now I can update the value easily:
Code:
#!/bin/sh
nsupdate -v << EOF
server 127.0.0.1
zone dyn.mydomain.example
update delete home.mydomain.example
update add home.dyn.mydomain.example. 5 IN A $ip_address
send
EOF


That's how I do it for my home machine. (In fact I run DNS on my home machine and then notify my linode to pick up the updates).

After that you just to decide on how you pick up your IP address and populate it. A simple CGI could do the job.

_________________
Rgds
Stephen
(Linux user since kernel version 0.11)


Top
   
 Post subject: Re: Custom dynamic DNS
PostPosted: Thu Sep 06, 2012 8:18 pm 
Offline
Senior Member
User avatar

Joined: Tue May 26, 2009 3:29 pm
Posts: 1691
Location: Montreal, QC
I did it via the Linode API. My domain is hosted on the Linode nameservers, so I created a subdomain with a low TTL, and I wrote a shell script on my home fileserver that checks if its IP has changed since the last check, and if it has, it changes the subdomain's IP via the linode API. I may or may not have based the script on something somebody else posted here previously (don't recall). I'll try to remember to post the script when I get home.


Top
   
 Post subject: Re: Custom dynamic DNS
PostPosted: Sat Sep 08, 2012 10:14 am 
Offline
Senior Newbie

Joined: Wed Feb 24, 2010 2:08 pm
Posts: 16
Sounds good, look forward to seeing the script :)


Top
   
 Post subject: Re: Custom dynamic DNS
PostPosted: Mon Sep 10, 2012 2:04 pm 
Offline
Senior Member
User avatar

Joined: Tue May 26, 2009 3:29 pm
Posts: 1691
Location: Montreal, QC
Aaand I completely forgot. Will try to remember tonight :)


Top
   
 Post subject: Re: Custom dynamic DNS
PostPosted: Mon Sep 10, 2012 7:57 pm 
Offline
Senior Member
User avatar

Joined: Tue May 26, 2009 3:29 pm
Posts: 1691
Location: Montreal, QC
Here's the shell script, with my various keys and IDs removed:

Code:
#!/bin/sh

LINODE_API_KEY=(PUT YOUR LINODE API KEY HERE)
DOMAIN_ID=(PUT YOUR DOMAIN ID HERE)
RESOURCE_ID=(PUT YOUR RESOURCE ID HERE)

WAN_IP=`wget -O - -q http://(PATH_TO_PHP_SCRIPT_HERE)`

OLD_WAN_IP=`cat /tmp/CURRENT_WAN_IP.txt`

if [ "$WAN_IP" = "$OLD_WAN_IP" ]; then
        echo "IP Unchanged"
else
        echo $WAN_IP > /tmp/CURRENT_WAN_IP.txt
        wget -qO- https://api.linode.com/?api_key="$LINODE_API_KEY"\&api_action=domain.resource.update\&DomainID="$DOMAIN_ID"\&ResourceID="$RESOURCE_ID"\&Target="$WAN_IP"
fi


And here's the PHP script that wget is calling:

Code:
<?php
echo $_SERVER['REMOTE_ADDR'];
?>


Put the PHP script on your server, fill in your API key, the two IDs, and the URL, and put the shell script in a cron job on the system whose IP you want to update (in my case, my home file server), and you're good to go.


Top
   
 Post subject: Re: Custom dynamic DNS
PostPosted: Mon Sep 10, 2012 8:56 pm 
Offline
Senior Member
User avatar

Joined: Sat Aug 30, 2008 1:55 pm
Posts: 1739
Location: Rochester, New York
You can also use the literal token '[remote_addr]' in place of an actual IP address for Target; this will do the right thing without needing a PHP script. (See http://www.linode.com/api/dns/domain.resource.update)

_________________
Code:
/* TODO: need to add signature to posts */


Top
   
 Post subject: Re: Custom dynamic DNS
PostPosted: Tue Sep 11, 2012 6:10 pm 
Offline
Senior Member
User avatar

Joined: Tue May 26, 2009 3:29 pm
Posts: 1691
Location: Montreal, QC
Ah, that'd be useful, although then you'd be unable to notice if the IP had changed, and would simply be asking Linode to update the DNS entry every few minutes. In any case, here's a script with that method (untested, writing this in the forum directly:

Code:
#!/bin/sh

LINODE_API_KEY=(PUT YOUR LINODE API KEY HERE)
DOMAIN_ID=(PUT YOUR DOMAIN ID HERE)
RESOURCE_ID=(PUT YOUR RESOURCE ID HERE)

wget -qO- https://api.linode.com/?api_key="$LINODE_API_KEY"\&api_action=domain.resource.update\&DomainID="$DOMAIN_ID"\&ResourceID="$RESOURCE_ID"\&Target=[remote_addr]


To shorten it even more you could just embed the API key and IDs right into the URL. The downside of this method is, as I said, it would hit Linode every time.


Top
   
 Post subject: Re: Custom dynamic DNS
PostPosted: Fri Sep 14, 2012 1:40 pm 
Offline
Senior Newbie

Joined: Wed Feb 24, 2010 2:08 pm
Posts: 16
Where do you get the domain and resource ID from?


Top
   
 Post subject: Re: Custom dynamic DNS
PostPosted: Fri Sep 14, 2012 6:42 pm 
Offline
Senior Member
User avatar

Joined: Tue May 26, 2009 3:29 pm
Posts: 1691
Location: Montreal, QC
IIRC you make an API request to get a list of the domains and take note of the IDs. First you do a domain.list:

http://www.linode.com/api/dns/domain.list

And then a domain.resource.list:

http://www.linode.com/api/dns/domain.resource.list

You can do the API calls right in your web browser, just build the URL of the request manually and take note of the results.


Top
   
 Post subject: Re: Custom dynamic DNS
PostPosted: Sun May 19, 2013 10:23 am 
Offline
User avatar

Joined: Sun May 19, 2013 10:18 am
Posts: 1
Since DynDNS is now requiring payment (or 30 day logins), I've updated a Python script from githib:

https://github.com/Andomar/LinodeDynDns

You can configure the script with a hostname, and it will look up the ResourceID and DomainID for you.

If you install Python, it works on Windows too.


Top
   
Display posts from previous:  Sort by  
Post new topic  Reply to topic


Who is online

Users browsing this forum: No registered users and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
RSS

Powered by phpBB® Forum Software © phpBB Group