Code Monkey home page Code Monkey logo

nsupdate's Introduction

Nameserver update for INWX (nsupdate)

This shell script implements dynamic DNS using the DomRobot XML-RPC API by INWX.
This script can update nameserver entries with your current WAN IPv4 and IPv6 addresses.

This way you can update your DNS records directly utilizing the INWX API and don't need the payed DynDNS option from INWX which uses DDNS over HTTP/S.

The minimum TTL when using the API is 300 seconds. The paid DynDNS option can go as low as 60 seconds.

Requirements

nsupdate is fully POSIX compliant and should work in every shell.

Nevertheless it has some dependencies to use it:

  • xmllint (Look for libxml2-utils (Debian, Ubuntu) or libxml2 (FreeBSD, CentOS)). It's used for Getting the ID and the current IP from the INWX API. This is the recommended way.

  • If you don't have installed xmllint, you need either nslookup or drill to query the nameserver for the current IP. In this case you must define the specific INWX IDs in the config files for your INWX records.

  • A hard requirement is curl as it's used to make the API calls.

Note: 2-Factor-Authentification method (2FA) is not supported when using the INWX API.

Installation

Simply clone this project or download the master.zip and extract it, e.g., using wget and 7z x master.zip.

Move the included nsupdate directory, which holds the configuration files, to /usr/local/etc/ (see the config section if you want to use another path) and nsupdate.sh anywhere in your $PATH (e.g. /usr/local/bin/ or ~/bin/).

Log directory

The default log directory is /var/log/nsupdate. You have to create this directory and ensure write access for the user that runs nsupdate (e.g. sudo mkdir -p /var/log/nsupdate && sudo chown $USER /var/log/nsupdate). When you want to use another path, see the config section.

Configuration

nsupdate.conf

nsupdate.conf is the main configuration file for nsupdate. Here you can set global defaults which can be used for all DNS records (e.g. INWX credentials, TTL, record type). These can be overwritten in the configuration files for your DNS records. There are also options to set the paths that are used by nsupdate.

See /usr/local/etc/nsupdate/nsupdate.conf.dist for all available options and their defaults.

All options except the INWX credentials have sensible defaults and can be left untouched if they suit your needs.

Configuring DNS records

The configuration files for your DNS belong to /usr/local/etc/nsupdate/conf.d/.

If you configured your INWX credentials in nsupdate.conf and the other defaults are fine for your use case, all you have to do is to set $MAIN_DOMAIN and $DOMAIN.

See /usr/local/etc/nsupdate/conf.d/sub.example.com_AAAA.conf.dist for an example with all available options.

Backwards compatibility

If you used nsupdate before, you should be able to use your existing configs. Some options have changed names but are recognized when processing the configuration files. This may change in the future.

Run nsupdate by cron

The best way to use nsupdate is by setting up a cron job (e.g. by running crontab -e).

To run the script every 5 minutes and suppress the output you can write something like */5 * * * * /usr/local/bin/nsupdate.sh > /dev/null 2>&1.

Changelog

2023-11-06

  • Added jq to Docker image (for processing json)

2022-12-14

  • Added Dockerfile
  • Added docker-compose.yml

2022-10-18

  • Completly rewritten. nsupdate is now a POSIX compliant /bin/sh script ๐Ÿ‘๐Ÿป
  • Backwards compatibility should be given (please test and report bugs!).
  • If using the xmmlint method, now also the IP for a record is retrieved this way
  • WAN IP now is only checked once per session instead of every time a new config is processed.
  • The script now automagically determines the best way to get the needed data (xmllint, nslookup, drill) and has some nice output options.
  • The code is now structured in functions which makes it more maintainable and modular.
  • Avoid using awk and get rid of dependency

2021-12-11

  • Added the possibility to retrieve the WAN IP by a shell command (e.g. SSHing into your router and get the IP of the WAN interface)

2020-07-03

  • Rearranged config.sample
  • Updated Readme
  • Getting the Domain-Record-ID via XML-RPC API

2020-05-11

  • Updated Readme with some hints
  • Updated config.sample with a hint for TTL

2020-03-31

  • Made time to live configurable

2019-12-20

  • Fixed DomRobot XML-RPC API syntax
  • Added some more documentation

2015-07-22

  • Changed the way how the existence of config files is checked
  • Updated the sample config file to reflect new options from the last updates
  • The script is reported to work in csh and sh too

2015-06-30

  • Fixed the check for config files. Can now handle more than one file
  • Changed warning for missing config files

2015-01-12

  • Added checks for needed commands
  • Added checks for existing config file
  • Added requirements to README.md

2014-02-21

  • Added support for IPv6
  • Added support for config files

2014-01-02

  • Changed default IP check site to ip.dblx.io
  • Added a switch to use drill instead of nslookup because FreeBSD 10 switched from bind to unbound
  • Renamed $HOSTNAME to $DOMAIN to work around potential conflicts with $HOSTNAME that's set by the host itself

2014-01-06

  • Config files are sourced relative to the script folder now

2013-07-12

  • First commit

License

nsupdate is distributed under the MIT license, which is similar in effect to the BSD license.

Copyright 2013 Christian Busch (http://github.com/chrisb86)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

nsupdate's People

Contributors

chrisb86 avatar elouin avatar ev21 avatar markcheret avatar phrosenberg avatar scho avatar schulzch avatar stefaba avatar vdecine avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

nsupdate's Issues

Suggestion: Only update when IP changed

Hello,

it is possible that the domain record only get updated when the ip address since last check (could be checked with the logs) have changed?

Currently I'm running the script every 10 minute to be sure that when the ip address is changed the domain is updated. I don't know if thats for inwx.de okay. :)

latest changes are missing after renaming master ->main

Hi @chrisb86 ,
as I can see the two latest commits (+2 merge) are missing.
I think it was done by the manual renaming of master -> main
Your local branch was not up to date so now some history is gone (not really I still have it on my fork https://github.com/EV21/nsupdate/commits/master ) - You can still fix it. - Just add my fork as remote, pull the changes and push it back to origin.

I think this should fix it:

git remote add ev21 [email protected]:EV21/nsupdate.git
git pull ev21 master
git push origin main

You could have waited for the release (announced to be released later in January) of the GitHub renaming tool. see https://github.com/github/renaming

nsupdate doesn't work on systems without xmllint

Hi there

thanks for your great work.
I want to let you know, that the wan_ip is never set on systems without xmllint.
The wan_ip part is currently nested in the xmllint check, when you put it into a separate function i.e. get_wan_ip and call that one after get_domain_info everything works like charm.

Cheers

parameter invalid

Hello,
I was just trying the script to update my INWX domain, but I get some error.

This is the output on CLI:

Starting nameserver update with config file ./nsupdate.d/www_example_org_AAAA.config (./nsupdate.sh.log)
<?xml version="1.0" encoding="UTF-8"?><methodResponse><params><param><value><struct><member><name>code</name><value><int>2005</int></value></member><member><name>msg</name><value><string>Parameter value syntax error</string></value></member><member><name>reasonCode</name><value><string>INVALID_CONTENT</string></value></member><member><name>reason</name><value><string>The following parameter is invalid: content</string></value></member><member><name>details</name><value><array><data><value><struct><member><name>code</name><value><string>PARAM_INVALID</string></value></member><member><name>msg</name><value><string>The parameter '' is invalid</string></value></member></struct></value></data></array></value></member><member><name>svTRID</name><value><string>20210927-163119648</string></value></member><member><name>runtime</name><value><double>0.002600</double></value></member></struct></value></param></params></methodResponse>Starting nameserver update with config file ./nsupdate.d/www_example_org_A.config (./nsupdate.sh.log

This is from the log:

Mon Sep 27 14:33:21 UTC 2021 - www.example.org updated. Old IP: ::1 New IP: 
Mon Sep 27 14:33:22 UTC 2021 - No update needed for www.example.org. Current IP: 192.0.2.22

Any idea why the IPv6 is not updated?

Unable to retrieve WAN_IP

For some reason the script is unable to retrieve WAN_IP. The dependencies are all met. The script is running on a OpenWrt Chaos Calmer Router.

$ cat nsupdate.config
# nsupdate.config

# from which site should we get your wan ip?
IP_CHECK_SITE="https://ip.dblx.io"

# use drill instead of nslookup for hostname lookup
USE_DRILL="YES"

# Use IPv6 connection
IPV6="NO"

# Update an MX record
MX="NO"

# Suppress all messages
SILENT=NO

# Login credentials for the inwx admin interface
INWX_USER="User"
INWX_PASS='XXXXXXX'

# The hostname that you want to update and it's ID from the inwx interface
# You get the ID when you edit the given nameserver entry and hover the save button.
DOMAIN="home.domain.de"
INWX_DOMAIN_ID="123456789"
$ cat nsupdate.sh.log 
Sat Jul 16 13:02:24 CEST 2016 - home.domain.de updated. Old IP: 77.21.146.128 New IP: 
Sat Jul 16 13:04:32 CEST 2016 - home.domain.de updated. Old IP: 77.21.146.128 New IP: 
Sat Jul 16 13:09:23 CEST 2016 - home.domain.de updated. Old IP: 77.21.146.128 New IP: 
Sat Jul 16 13:16:30 CEST 2016 - No update needed for home. Current IP: 
Sat Jul 16 13:17:50 CEST 2016 - No update needed for home. Current IP: 
Sat Jul 16 13:18:14 CEST 2016 - home.domain.de updated. Old IP: 77.21.146.128 New IP: 
Sat Jul 16 13:20:13 CEST 2016 - No update needed for home.domain.de. Current IP: 
Sat Jul 16 13:22:23 CEST 2016 - home.domain.de updated. Old IP: 77.21.146.128 New IP:

Is this a issue with https://ip.dblx.io? If so, are there any alternatives available?

WAN_IP is not set

Hi,
I've encountered a strange bug. The WAN_IP is sometimes blank and then the script updates the DNS entry (which I presume doesn't work since it's blank). This only happens when I run the script. Running the curl command by hand works like a charm. It's bit strange. I might update the script in order that it fails whenever WAN_IP or NSLOOKUP is blank/not set.

Cheers,
scho

parse error. not well formed.

I got this error-message:


Starting nameserver update with config file ./nsupdate.d/nsupdate.config
<?xml version="1.0" encoding="UTF-8"?><methodResponse><fault><value><struct><member><name>faultString</name><value><string>parse error. not well formed.

error occurred at line 17, column 50, byte index 561</string></value></member><member><name>faultCode</name><value><int>-32700</int></value></member></struct></value></fault></methodResponse>

Is there a problem with the inwx-API or the script?

Getting the Domain-Record-ID via XML-RPC API

For convenience reasons it would be very nice especially for new user so they don't need to lookup HTML code elements.
I already did some tests, it took some time because there are no examples in the documentation for this case.

I think it is ready for implementation.
I don't know if the used XML-Parser is available on most systems. Maybe there are other options.

New dependency as an option would be:

  • xmllint (libxml2-utils)

You can try this:

#/usr/bin/env bash

INWX_USER="NiceUserName"
INWX_PASSWORD="VeryStrongPassword"
MAIN_DOMAIN="example.de"
DOMAIN="home.example.de"
TYPE="AAAA"

API_INFO_REQUEST="<?xml version=\"1.0\"?>
<methodCall>
 <methodName>nameserver.info</methodName>
 <params>
    <param>
       <value>
          <struct>
             <member>
                <name>user</name>
                <value>
                   <string>$INWX_USER</string>
                </value>
             </member>
             <member>
                <name>lang</name>
                <value>
                   <string>en</string>
                </value>
             </member>
             <member>
                <name>pass</name>
                <value>
                   <string>$INWX_PASSWORD</string>
                </value>
             </member>
             <member>
                <name>domain</name>
                <value>
                   <string>$MAIN_DOMAIN</string>
                </value>
             </member>
             <member>
                <name>name</name>
                <value>
                   <string>$DOMAIN</string>
                </value>
             </member>
             <member>
                <name>type</name>
                <value>
                   <string>$TYPE</string>
                </value>
             </member>
          </struct>
       </value>
    </param>
 </params>
</methodCall>"

# The full xpath
# XPATH='string(/methodResponse/params/param/value/struct/member[name="resData"]/value/struct/member[name="record"]/value/array/data/value/struct/member[name="id"]/value/int)'
# A short version of the xpath
XPATH='string(//member[name="id"]/value/int/text())'

ID=$(curl -s -X POST https://api.domrobot.com/xmlrpc/ \
-H "Content-Type: application/xml" \
-d "$API_NFO_REQUEST" \
| xmllint --xpath $XPATH -)

#curl -X POST https://api.domrobot.com/xmlrpc/ \
#-H "Content-Type: application/xml" \
#-d "$API_INFO_REQUEST"

# If you want a beautiful formatted XML-output use this (pipe):
#| xmllint --format -

#The AAAA-Type Record-ID of home.example.de is: 123456789
echo $(printf "The %s-Type Record-ID of %s is: %s" "$TYPE" "$DOMAIN" "$ID")

Config File not Found

Hello,

when I try to run the script as a cron job, no config file is found. When I try to run it via ssh, everything works fine. A workaround for me was to write a script, which cd's into the folder of the script and then executes it.

Thanks a lot for your work on this script.

Best regards
Andreas

Edit: Another workaround is to disable the config file check.

OS: FreeNAS-9.3-STABLE-201506292130

USE_DRILL = YES means IPV6-Update everytime

Hello,

I've got an issue on IPV6-Updates. If the Option USE_DRILL is set to yes i get everytime NSLOOKUP=AAAA - so everytime my IPV6 gets updated:

So 9. Aug 19:10:03 CEST 2015 - _._.*** updated. Old IP: AAAA New IP: ::

When USE_DRILL = NO the IP doesn't need an update.

So 9. Aug 20:36:02 CEST 2015 - No update needed for _..**. Current IP: *::_

IPV4 works well with USE_DRILL = YES or NO.

I'm not sure if this really is a problem or if it should be like this. I'm so happy that i found that script - but actually i don't understand it 100% - and can't really create a patch. Sorry.

Greetings,
Jonathan

Get external IP "locally"

Behind a router it's possible to get the external IP directly through upnp.
E.g. miniupnp ships with a neat script named external-ip which just returns the external IP without pinging some arbitrary online service.

Authentication error

since two days ddclient isnt working anymore. i searched the internet for an alternative and found this script. i configured everything like i should and got an "Authentication error" back when running the script. manually updating ip works fine so my login data should be correct. do i miss something?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.