DynDNS mit nsupdate
Aus NeoWiki
Diese Seite wird nicht mehr weiter gepflegt!
Inhaltsverzeichnis |
Requirements
- das Tool "nsupdate" aus dem Paket "dnsutils"
- Bind DNS
- Linux Box mit statischer IP Adresse :)
Konfiguration des BIND DNS
/etc/bind/named.conf
Zeilen zufügen:
- include "/etc/bind/named.conf.keys";
- include "/etc/bind/named.conf.dyndns";
/etc/bind/named.conf.keys
Das Secret wird mit folgendem Kommando erstellt und muss von Hand eingefügt werden:
- dnssec-keygen -a HMAC-MD5 -b 512 -n HOST dyndns.neo-soft.org
<keydata> ist der lange ununterbrochene String innerhalb einer der beiden Schlüsseldateien.
key dyndns.neo-soft.org {
algorithm HMAC-MD5;
secret "<keydata>";
};
/etc/bind/named.conf.dyndns
zone "dyndns.neo-soft.org" {
type master;
file "/var/cache/bind/dyndns.neo-soft.org.hosts";
allow-update {
key dyndns.neo-soft.org.;
};
};
/var/cache/bind/dyndns.neo-soft.org.hosts
Vor der ersten Updateanfrage kann die Datei erstellt werden. Danach sind keine manuellen Änderungen mehr möglich
$ORIGIN .
$TTL 8400 ; 2 hours 20 minutes
dyndns.neo-soft.org IN SOA ns. root. (
2007072513 ; serial
7200 ; refresh (2 hours)
900 ; retry (15 minutes)
1857600 ; expire (3 weeks 12 hours)
8400 ; minimum (2 hours 20 minutes)
)
NS ns.dyndns.neo-soft.org.
$ORIGIN dyndns.neo-soft.org.
ns A 78.47.210.173
$TTL 60 ; 1 minute
Einrichtung einer Delegation an dieses neue DNS, falls die Domain von einem anderen DNS verwaltet wird
Folgende Zeile zur Delegation in die Domain-Zone eintragen:
dyndns 1800 IN NS ns.dyndns @ IN A 78.47.210.173 * IN A 78.47.210.173 ns.dyndns 3600 IN A 78.47.210.173
Einrichtung einer Updateschnittstelle via http(s)
Einrichtung der notwendigen MySQL Tabelle
CREATE TABLE `dyndns_accounts` ( `id` int(11) NOT NULL auto_increment, `user` varchar(20) NOT NULL, `password` varchar(20) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `user` (`user`) ) ENGINE=MyISAM;
/var/www/http/ns.dyndns/update.php
<?php
if (!isset($_GET["account"]))
die("404");
$DB = "dyndns_db";
$adminpass = "adminpassword";
$IP = $_SERVER["REMOTE_ADDR"];
$ACCOUNT = $_GET["account"];
$ACCOUNT = split(":",$ACCOUNT);
$USER = $ACCOUNT[0];
$PASS = $ACCOUNT[1];
if ($USER=="" || $PASS=="")
die("500");
if ($USER=="admin" && $PASS==$adminpass)
admin();
else {
//verify password
mysql_connect("mysql_hostname","mysql_username","mysql_password")
or die("Database not responding, try again later!");
$SQL = "SELECT * FROM dyndns_accounts WHERE user='$USER';";
$res = mysql_db_query($DB,$SQL);
$row = mysql_fetch_array($res);
if ($row["password"]!=$PASS) {
echo "Could not authenticate this account.";
} else {
// update DNS record
$DNS = "server 78.47.210.173\nzone dyndns.neo-soft.org\nupdate delete ".$USER.".dyndns.neo-soft.org\nupdate add ".
$USER.".dyndns.neo-soft.org 60 A ".$IP."\nsend\nquit\n";
echo "Update Request: ".nl2br($DNS);
exec("echo \"".$DNS."\" | nsupdate -v -d -k /etc/bind/Kdyndns.neo-soft.org.+157+60057.private",$res);
// echo "DNS Response: ".implode("<br>",$res);
$IPnew = gethostbyname($USER.".dyndns.neo-soft.org");
echo "DNS Query = ".$IPnew." --> ";
if ($IP==$IPnew)
echo "UPDATE SUCCESSFUL"; else echo "UPDATE FAILED";
}
mysql_close();
}
Update der IP Adresse über diese Webschnittstelle
Einfach nur folgende URL aufrufen:
Das lässt sich auch per cronjob automatisieren :)
#!/bin/sh cd /tmp rm update.php* 2>/dev/null wget http://yourhost/update.php?account=dyndnshostname:passwort 2>/dev/null
Siehe auch
Dieses Howto wurde entwickelt aus dem Inhalt folgender Seite:
TODO
Kompatibilität zu dyndns.com herstellen für hardware router