DDNS
From Wildsong
When a server is behind a firewall I want to know when the server's public IP address changes, and to communicate it back to my DNS servers at dns.he.net.
I need to know the outside IP address, not the private IP address of the server itself.
DDNS on Debian servers
HE.net part: Create a key. You have to create a key on the DNS server so that it will trust updates coming from the Debian server.
- Log into dns.he.net
- Go to the appropriate domain
- Click on the entry for the server (create one if it does not exist)
- Check the box "Enable entry for dynamic DNS. This will also clear the current IP address and set TTL to 5 minutes.
- Click Update.
- There will now be a "recycle" type icon for the entry. Click on it to either enter a key or generate a random key.
Debian: Install and configure a DDNS package.
sudo apt-get install ddclient
/etc/ddclient.conf
# /etc/ddclient.conf protocol=dyndns2 use=cmd # Read ip address from Mikrotik cmd=/usr/local/sbin/get_ip.py server=dyn.dns.he.net login=bellman.wildsong.biz password='eOYop3nMoEaT4a4U' daemon=3600 # check every hour syslog=yes # log update msgs to syslog mail=root # mail all msgs to root mail-failure=root # mail failed update msgs to root pid=/var/run/ddclient.pid # record PID in file. bellman.wildsong.biz
Getting the outside IP address
/usr/local/sbin/get_ip.py contains
#!/usr/bin/env python # # Read our outside IP address from the Mikrotik router. # import sys,subprocess import re args = ['ssh', '[email protected]', '/ip address print'] re_ip = re.compile(r'^ 1 D ([\d\.]+)') p = subprocess.check_output(args) for line in p.split('\n'): mo = re_ip.search(line) if mo: print mo.group(1) exit(0) exit(-1)
This script relies on an account with an SSH key pair so that it can run commands on the router without requiring a password.
Mikrotik "/IP/Cloud" Service
This uses DDNS to talk to a service hosted by Mikrotik, we don't need it right now.