nsd-dyndns/README.md

132 lines
4.1 KiB
Markdown
Raw Permalink Normal View History

2018-04-29 18:39:07 +00:00
# nsd-dyndns
2018-04-29 19:05:02 +00:00
## Introduction
nsd-dyndns is a simple script that adds dynamic DNS dunctionality to NSD (authoritative DNS name server).
## Requirements
The following is required or suggested:
* OpenBSD (or another BSD or some Linux distro) with HTTPD and NSD installed (pkg_add nsd), configured and running
* (sub-)domain for your webserver. Needed for updating the NS record of your actual DynDNS domain.
2018-04-29 19:20:00 +00:00
* In this example: _update.example.com_
* (sub-)domain that is updated dynamically.
2018-04-29 19:20:00 +00:00
* In this example: _dyn.example.com_
2018-04-29 19:05:02 +00:00
* A router capable of sending custom GET-requests to your DynDNS server.
* In this example: A FritzBox
## Installation
### Configure your web server
#### Apache/httpd
Add the following new virtual host to your _/etc/httpd.conf_:
2018-04-29 19:05:02 +00:00
```
server "update.example.com" {
2018-04-29 19:05:02 +00:00
listen on $ext_addr port 80
root "/htdocs/dyndns"
log access dyndns.log
}
```
#### nginx
Add the following to your nginx.conf. The "access" log format isn't avaliable by default so you have to define it.
```
http {
...
log_format access '$host $remote_addr - $remote_user [$time_local] '
'"$request" $status $body_bytes_sent '
'"$http_referer" "$http_user_agent" "$gzip_ratio"';
...
server {
listen 80;
server_name update.example.com;
root /htdocs/dyndns;
access_log /var/www/logs/dyndns.log access;
...
}
}
```
2018-04-29 19:20:00 +00:00
Create an empty _update.html_:
2018-04-29 19:05:02 +00:00
```
# mkdir /var/www/htdocs/dyndns/
# touch /var/www/htdocs/dyndns/update.html
```
After reloading webserver, try to access http://update.example.com/update.html
2018-04-29 19:20:00 +00:00
The request should show up in _/var/www/logs/dyndns.log_
2018-04-29 19:05:02 +00:00
### Create a zone file for dyn.example.com
2018-04-29 19:20:00 +00:00
Create a new zone file (e.g. at _/var/nsd/zones/dyn.example.com.zone_) with the following content
2018-04-29 19:05:02 +00:00
```
$ORIGIN example.com.
$TTL 300
@ IN SOA ns1.example.com. admin.example.com. (
1524952218
300 ; refresh
900 ; retry
1209600 ; expire
1800 ; ttl
)
; Name servers
IN NS ns1.example.com.
2018-05-07 08:00:40 +00:00
IN NS ns2.example.com.
2018-04-29 19:05:02 +00:00
; A records
@ IN A 123.123.123.123
update IN A 123.123.123.123
2018-05-01 09:25:02 +00:00
dyn IN A 123.123.123.123
2018-04-29 19:05:02 +00:00
```
Don't forget to set your own domain names, name servers and ip addresses
2018-04-29 19:20:00 +00:00
Furthermore, add this zone file to your _/var/nsd/etc/nsd.conf_
2018-04-29 19:05:02 +00:00
### Configure and Install nsd-dyndns
* Copy _dyndns.conf-dist_ to _/etc/dyndns.conf_
2018-04-29 19:24:15 +00:00
* _# cp dyndns.conf-dist /etc/dyndns.conf_
2018-04-29 19:05:02 +00:00
* Edit _/etc/dyndns.conf_ to your needs
* Copy _dyndns.sh_ to _/usr/local/bin/dyndns.sh_
2018-04-29 19:24:15 +00:00
* _# cp dyndns.sh /usr/local/bin/dyndns.sh_
2018-04-29 19:05:02 +00:00
* Make the script executable:
* _# chmod u+x /usr/local/bin/dyndns.sh_
* Add _/usr/local/bin/dyndns.sh_ to your crontab
2018-04-29 19:20:00 +00:00
### Configure your router
Configure your router to query the following URL:
2018-04-29 19:05:02 +00:00
```
2018-04-29 19:20:00 +00:00
update.example.com/update.html?qwertzuiop1234567890
```
Don't forgert to set your own domain name and to replace the string after "?" with the password you configured in the config file.
### What it does
When your router gets a new IP and therefore sends an HTTP request to your server, a similar entry should appear in your _/var/www/logs/dyndns.log_:
2018-04-29 19:05:02 +00:00
```
2018-04-29 19:24:52 +00:00
update.example.com 123.123.123.123 - - [29/Apr/2018:20:48:19 +0200] "GET /update.html?qwertzuiop1234567890 HTTP/1.1" 200 6
2018-04-29 19:20:00 +00:00
```
When the script is executed e.g. via cron, the following happens:
* It greps the last line of _/var/www/logs/dyndns.log_ where the correct password was found and extracts the requesting IP address
* It checks if this IP is the same than the last time
* If it's a new IP, then it replaces the forth line in your zone file - the line with the version number - with a new version (current unix time stamp)
* As a second step, it updates the A record of you DynDNS domain (dyn.example.com in our example)
* It then stores the new IP in the file _/tmp/last_dyndns_ip.txt_
* Finally it reloads NSD