Problem
You have a crappy internet provider who hands out dynamic IPv4 addresses and IPv6 prefixes, but you can’t remember all those numbers and want to use DNS as intended. Actually, I have 2 internet providers, Vodafone and Telekom, each with its own problems . Vodafone’s IPv6 prefix seems to be static for now, but they blessed me with DS-Lite after the update to 400 Mbit. Telekom has a dual stack, but the public IPv4 address and the delegated IPv6 prefixes are highly dynamic.
What you need
- A DNS zone and control over the zone file, so you can delegate a subdomain to another name server
- The “another name server” with a static IP. If you don’t have that, stop reading!
- a script for the dynamic updates
I have a root server and a DNS zone at Hetzner. The root Server has a static IPv4 address and IPv6 prefix. Also, they let you edit the pure bind zone file via a text box, not a form! Since I’m a perl guy, I did the script in my favorite perfect and easy readable language.
Configure your “another name server”
Install bind on your box with the static IP. Then generate a key for dynamic updates. Do not use dnssec-keygen as described in various tutorials. You will fail! Use ddns-confgen instead and follow the instructions in the comment. Your zone file should look something like this:
...
// THE key
key "ddns-key.dyn.d-tor.org" {
algorithm hmac-sha256;
secret "base64stufffromddns-confgen=";
};
// THE dynamic zone
zone "dyn.d-tor.org." {
update-policy { grant ddns-key.dyn.d-tor.org zonesub ANY; };
type master;
file "dyn.d-tor.org.hosts";
};
...
The above snippet configures the zone dyn.d-tor.org and allows updates to anyone who has THE key. Next, create the initial zone file in the directory specified by the “directory” directive in named.conf (on ArchLinux it’s the default /var/named, thus /var/name/dyn.d-tor.org.hosts):
$ORIGIN .
$TTL 600 ; 10 minutes
dyn.d-tor.org IN SOA valhalla.d-tor.org. me.d-tor.org. (
1 ; serial
500 ; refresh (8 minutes 20 seconds)
500 ; retry (8 minutes 20 seconds)
86400 ; expire (1 day)
500 ; minimum (8 minutes 20 seconds)
)
NS valhalla.d-tor.org.
Then restart/reconfigure bind and check for errors:
# systemctl restart named
# journalctl -u named
If you have ip(6)tables running, allow access to port 53 UDP and TCP for good measure:
# iptables -I INPUT 2 -p udp --dport 53 -j ACCEPT
# iptables -I INPUT 2 -p tcp --dport 53 -j ACCEPT
# iptables -I INPUT 2 -p udp --dport 53 -j ACCEPT
# iptables -I INPUT 2 -p tcp --dport 53 -j ACCEPT
Copy the key to the box where you want to update from, e.g. /etc/ddns.key and set permissions to 600. It should contain only the key section:
key "ddns-key.dyn.d-tor.org" {
algorithm hmac-sha256;
secret "base64stufffromddns-confgen=";
};
Now test it:
# nsupdate -k /etc/ddns.key <<EOF
> server 2a02:4f8:2a:254e::2
> update delete blub.dyn.d-tor.org A
> update add blub.dyn.d-tor.org 200 A 191.139.50.71
> send
> EOF
If you’ve done everything right:
# host blub.dyn.d-tor.org 2a02:4f8:2a:254e::2
blub.dyn.d-tor.org has address 191.139.50.71
Delegate the Zone
Now we need to delegate dyn.d-tor.org to 2a02:4f8:2a:254e::2. Add this to the zone file on your authoritative name server (in my case, Hetzner):
...
dyn IN NS dyndns ; delegation to dyndns.d-tor.org
dyndns IN AAAA 2a02:4f8:2a:254e::2 ; IPv6 glue record for dyndns.d-tor.org
dyndns IN A <IPv4.address.of.dyndns> ; IPv4 glue record
...
Wait for the information to spread. Check with dnstracer:
# dnstracer -s . dyn.d-tor.org
If you get a result, we can continue 🙂
THE script
Write a script that extracts the IP addresses from your interfaces and uses nsupdate to update the records. It shouldn’t be that hard. Sorry, I can’t provide mine, because it is very specific to my setup.