Skip to content

It synchronizes the external IP address with the DNS record in the OVH or Cloudflare.

License

Notifications You must be signed in to change notification settings

Wojteek/dynhost

Repository files navigation

DynHost

The simplest tool for fetching and saving the external IP address in the DNS record of your own domain. It supports the OVH and Cloudflare.


Motivation

This code was created in Golang for a few reasons. I've needed some tool for updating an external IP in OVH (that option is called DynHost in the management panel). Why? First of all, my Internet service provider doesn't guarantee that the IP address wouldn't change.

Use case

I've wanted to create a OpenVPN service on my Raspberry PI. As I've written above my ISP doesn't guarantee the permanent IP address. In that case I needed some tool for updating the DynHost in OVH to use my dedicated domain name instead of using the dynamic IP address for connecting.

How to use it?

./bin/dynhost [global options] command [command options] [arguments...]

Docker (recommended)

To run this application as Docker image you can use:

docker run -v $(pwd)/data.json:/app/data.json wojteek/dynhost:latest --help

Each version of this tool is tagged by version of release so instead of using latest tag you can use a specific version.

docker-compose.yml

version: "3"
services:
  dynhost:
    image: wojteek/dynhost:latest
    command: [
      "--timer=15m",
      "cloudflare",
      "--auth-token=YOUR_AUTH_TOKEN",
      "--zone-id=YOUR_ZONE_ID",
      "--dns-id=YOUR_DNS_ID",
      "--hostname=dynhost.example.com",
    ]
    container_name: "dynhost"
    restart: always
    volumes:
      - ./data.json:/app/data.json:rw

Building from the source

In order to build this tool you can just run:

make build-app

Global options

--data value    Set the path of the JSON file with the data of an application (default: "data.json")
--timer value   Set the interval between automatic checking of an external IP address (default: 0s)
--debug         Enable the debug mode (default: false)
--help, -h      Show help (default: false)
--version, -v   Print the version (default: false)

List of all commands

cloudflare [command options] [arguments...] - Cloudflare provider

Note: Don't use the Global API Key at Cloudflare. This tool supports the API Token, that's why I recommend you to create a new one (Zone.DNS with Edit permission - as additional step you can specific zone)

Options

--auth-token value  The authentication token of the Cloudflare API [$CLOUDFLARE_AUTH_TOKEN]
--zone-id value     The zone identifier (Cloudflare DNS) [$CLOUDFLARE_ZONE_ID]
--dns-id value      The dns identifier (Cloudflare DNS) [$CLOUDFLARE_DNS_ID]
--hostname value    The hostname (Cloudflare DNS) [$CLOUDFLARE_HOSTNAME]

ovh [command options] [arguments...] - OVH provider

Visit the documentation if you don't have the credentials of the DynHost option.

Options

--auth-username value  The authentication username of the DynHost option [$OVH_AUTH_USERNAME]
--auth-password value  The authentication password of the DynHost option [$OVH_AUTH_PASSWORD]
--hostname value       The hostname of the DynHost option [$OVH_HOSTNAME]

Auto start

If you would like to add this tool to the service manager (for example for auto-starting), I recommend you to use systemd. Bellow there is a sample configuration which is used by me. You just have to adjust this configuration to yourself.

[Unit]
Description="DynHost"

[Service]
User=YOUR_USER
ExecStart=/path/to/dynhost [global options] command [command options] [arguments...]
Restart=always
RestartSec=10s
KillMode=process
TimeoutSec=infinity

[Install]
WantedBy=multi-user.target

In my case (Raspbian) the configuration is located in: /lib/systemd/system/dynhost.service