Skip to content

Update AWS Route53 hosted zone with current public IP address. Alternative to Dynamic DNS services such as Dyn, No-IP, etc

License

Notifications You must be signed in to change notification settings

chadhutchins182/route53-dynamic-dns

 
 

Repository files navigation

chadhutchins182/route-53-dynamic-dns

FOR RASPBERRY PI 4

Please Visit sjmayotte/route53-dynamic-dns for the general container.


Status build Docker Pulls Docker Image Size (latest) GitHub Issues GitHub Pull Requests License

Update Amazon Route53 hosted zone with current public IP address (from OpenDNS or ifconfig). No cost alternative to DynamicDNS services such as Dyn, No-IP, etc. Designed to be simple and efficient with the ability to run as a Node.js process or in a Docker Container.

Table of Contents

Environment Variables

Environment variables are required to run the process as standalone Node.js process or Docker Container.

  • AWS_ACCESS_KEY_ID - string - AWS Access Key for IAM user; see: AWS Javascript SDK - Getting Started
  • AWS_SECRET_ACCESS_KEY - string - AWS Secret Access Key for IAM user; see: AWS Javascript SDK - Getting Started
  • AWS_REGION - string - AWS Region; ex: "us-east-1"; List of regions: AWS Javascript SDK - Setting Region
  • ROUTE53_HOSTED_ZONE_ID - string - AWS Route53 Hosted Zone ID; ex: "Z25S75OFY0ERQD"
  • ROUTE53_DOMAIN - string - AWS Route53 FQDN; ex: "home.example.com"
  • ROUTE53_TYPE - string - AWS Route 53 record type for FQDN; ex: "A"
  • ROUTE53_TTL - integer - AWS Route 53 TTL in seconds for FQDN; ex: 60
  • SEND_EMAIL_SES - boolean (case sensative), default: false - Use AWS SES to send notification email. ex: true
  • SES_TO_ADDRESS - string - If SEND_EMAIL_SES = true then required, 'To' address for email; ex: "admin@example.com"
  • SES_FROM_ADDRESS - string - If SEND_EMAIL_SES = true then required, 'From' address for email; ex: "notification@example.com"
  • UPDATE_FREQUENCY - integer, default: 60000 (1m) - Interval in Milliseconds to check if Public IP has changed; ex: 60000 (which is every minute)
  • IPCHECKER - string, default: opendns - Public IP checker service. 'opendns' or 'ifconfig.co'
  • LOG_TO_STDOUT - boolean (case sensative), default: false - Flag to set log to STDOUT rather than to the application log file.

Minimum AWS IAM Policy

Below are examples of minimium IAM policies for Route53 and SES

Route53

{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Sid": "VisualEditor0",
            "Effect": "Allow",
            "Action": "route53:ChangeResourceRecordSets",
            "Resource": "arn:aws:route53:::hostedzone/*"
        },
        {
            "Sid": "VisualEditor1",
            "Effect": "Allow",
            "Action": "route53:TestDNSAnswer",
            "Resource": "*"
        }
    ]
}

SES

{
    "Effect": "Allow",
    "Action": "ses:SendEmail",
    "Resource": "*",
    "Condition": {
        "ForAllValues:StringLike": {
            "ses:Recipients": [
                "you@example.org"
            ]
        }
    }
}

Usage

Docker

Image is built from official node:alpine image, which runs on the popular Alpine Linux project. Alpine Linux is much smaller than most distribution base images (~5MB), which leads to much slimmer images in general. If you are not familiar with Docker, please start by reading Getting Started section of Official Docker Documentation.

Versions

chadhutchins182/route53-dynamic-dns-arm32v7:latest

Points to latest stable version.

Pull Image

Pull image from DockerHub. Replace [version] with desired version (ex: v1.2.0).

$ docker pull chadhutchins182/route53-dynamic-dns-arm32v7:[verison]

Run Container Examples

See Docker Run Reference for full list of options.

Minimium ENV Variables

Run container with default values (see: Environment Variables)

$ docker run -d -t -i --rm \
    --name route53-dynamic-dns \
    -e AWS_ACCESS_KEY_ID=[SECRET] \
    -e AWS_SECRET_ACCESS_KEY=[SECRET] \
    -e AWS_REGION=[REGION] \
    -e ROUTE53_HOSTED_ZONE_ID=[value] \
    -e ROUTE53_DOMAIN=[value] \
    -e ROUTE53_TYPE=[value] \
    -e ROUTE53_TTL=[value] \
    chadhutchins182/route53-dynamic-dns-arm32v7:[verison]

Enable SES Emails

Run container with SES Emails (see: Environment Variables)

$ docker run -d -t -i --rm \
    --name route53-dynamic-dns \
    -e AWS_ACCESS_KEY_ID=[SECRET] \
    -e AWS_SECRET_ACCESS_KEY=[SECRET] \
    -e AWS_REGION=[REGION] \
    -e ROUTE53_HOSTED_ZONE_ID=[value] \
    -e ROUTE53_DOMAIN=[value] \
    -e ROUTE53_TYPE=[value] \
    -e ROUTE53_TTL=[value] \
    -e SEND_EMAIL_SES=true \
    -e SES_TO_ADDRESS=[value] \
    -e SES_FROM_ADDRESS=[value] \
    chadhutchins182/route53-dynamic-dns-arm32v7:[verison]

Full Configuration

Run container with all options (see: Environment Variables). LOG_TO_STDOUT=true is recommended setting in container.

$ docker run -d -t -i --rm \
    --name route53-dynamic-dns \
    -e AWS_ACCESS_KEY_ID=[SECRET] \
    -e AWS_SECRET_ACCESS_KEY=[SECRET] \
    -e AWS_REGION=[REGION] \
    -e ROUTE53_HOSTED_ZONE_ID=[value] \
    -e ROUTE53_DOMAIN=[value] \
    -e ROUTE53_TYPE=[value] \
    -e ROUTE53_TTL=[value] \
    -e SEND_EMAIL_SES=[true or false] \
    -e SES_TO_ADDRESS=[if SEND_EMAIL_SES = true then value else empty] \
    -e SES_FROM_ADDRESS=[if SEND_EMAIL_SES = true then value else empty] \
    -e UPDATE_FREQUENCY=60000 \
    -e IPCHECKER=ifconfig.co \
    -e LOG_TO_STDOUT=true \
    chadhutchins182/route53-dynamic-dns-arm32v7:[verison]

View Useful Container Data

Determine CONTAINER ID for container started in previous step.

$ docker ps -a

Sample output

CONTAINER ID    IMAGE                           COMMAND        CREATED            STATUS            PORTS       NAMES
9998c92ff8a1    chadhutchins182/route53-dynamic-dns-arm32v7   "npm start"    45 seconds ago     Up 44 seconds                 route53-dynamic-dns

View logs of STDOUT from CONTAINER ID (copy from output above)

$ docker logs [CONTAINER ID]

View Node.js process log, which is written to application.log in project root directory. See: Logs for more details.

$ docker exec -it [CONTAINER ID] sh
/usr/src/app > ls -la
/usr/src/app > tail -f application.log

If running container with LOG_TO_STDOUT=true you will see logs in STDOUT.

Podman

Podman is a daemonless container engine for developing, managing, and running OCI Containers on your Linux System. There are no daemons in the background doing stuff, and this means that Podman can be integrated into system services through systemd. Podman implements almost all the Docker CLI commands (apart from the ones related to Docker Swarm, of course).

Running Container on RHEL8 or CentOS8

Below are steps to create a service in systemd to run a podman container the starts on boot.

If SELinux is enabled on your system, you must turn on the container_manage_cgroup boolean to run containers with systemd.

$ setsebool -P container_manage_cgroup on

Create file in /etc/systemd/system/[service-name] for systemd configuration. In example below we assume [service-name] = r53-dydns-container.service.

$ vi /etc/systemd/system/r53-dydns-container.service

Add contents below to file. Replace [env] with Environment Variables. Example below uses chadhutchins182/route53-dynamic-dns-arm32v7:v1.1

[Unit]
Description=Route53 Dynamic DNS Container
After=network.target

[Service]
Type=simple
TimeoutStartSec=5m
ExecStartPre=-/usr/bin/podman rm "r53-dydns"

ExecStart=/usr/bin/podman run -it --name r53-dydns -e AWS_ACCESS_KEY_ID=[value] -e AWS_SECRET_ACCESS_KEY=[value] -e AWS_REGION=[value] -e ROUTE53_HOSTED_ZONE_ID=[value] -e ROUTE53_DOMAIN=[value] -e ROUTE53_TYPE=[value] -e ROUTE53_TTL=[value] -e SEND_EMAIL_SES=[value] -e SES_TO_ADDRESS=[value] -e SES_FROM_ADDRESS=[value] -e UPDATE_FREQUENCY=[value] -e IPCHECKER=[value] -e LOG_TO_STDOUT=[value] chadhutchins182/route53-dynamic-dns-arm32v7:[tag]

ExecReload=-/usr/bin/podman stop "r53-dydns"
ExecReload=-/usr/bin/podman rm "r53-dydns"

ExecStop=-/usr/bin/podman stop "r53-dydns"

Restart=always
RestartSec=30

[Install]
WantedBy=multi-user.target

Configure systemd service.

# Reload files for systemd
$ systemctl daemon-reload

# Start service
$ systemctl start r53-dydns-container.service

# Determine status of service
$ systemctl status r53-dydns-container.service

# If all looks good enable at start-up
$ systemctl enable r53-dydns-container.service

Take a look at the container that is running. Remember to use elevated permission if needed.

# Find running containers
$ podman ls -la

# Access shell in container
$ podman exec -it [container_id] sh

# Stop container with systemd
$ systemctl stop r53-dydns-container.service

# Start container with systemd
$ systemctl start r53-dydns-container.service

# Reload container with systemd
$ systemctl reload r53-dydns-container.service

Node.js Process

Steps below assume you have Node.js and NPM installed on machine. If you do not, please download and install Node.js and NPM before proceeding. Process confirmed to work on Node v14.

Download Release

Download release version from release repository. For example, you can use v1.2.0.tar.gz to download source for release tag v1.2.0.

$ curl -sL https://github.com/chadhutchins182/route53-dynamic-dns/archive/[version] | tar xz
$ cd route53-dynamic-dns

Set Environment Variables

You have the option to pass environment variables at runtime or populate environment variables in .env. Release package includes .env.example, which can be renamed to .env and populated with values. The process expects .env will be in root of directory structure.

$ cp .env.example .env
$ vi .env
$ # Update .env with values and save file
$ rm .env.example

See [Minimium ENV Variables]((minimium-env-variables) for example of minimium configuration.

Installation

Project uses NPM package manager. Install dependencies from package.json.

$ npm install

Run Process

Start Node.js process which will run forever (or until process is stopped by user).

$ npm start

The Node.js process writes useful data to log files. See Logs section for more information.

Logs

STDOUT

When Node.js process starts it writes useful data to STDOUT. Example output:

Log4js initialized with level INFO 

Logs located in application.log in working directory

If running in Docker Container use the following command to access a shell:
   docker exec -it [container_id] sh

If you set ENV variable LOG_TO_STDOUT=true then logs will send to STDOUT.

application.log

Application logs are written to application.log in root project directory. Log files are compressed and archived after reaching 10MB in size. The most recent 3 archives are kept in rotation. All other archives are deleted to keep footprint small. This is ignored if LOG_TO_STDOUT=true.

Issues

If you run into any issues, check to make sure all variables are set properly in .env or passed properly into Docker Container at runtime. If you are sure your environment variables are correct, please open an issue and provide as much detail as possible.

License

MIT

Route53 Dynamic DNS is licensed under the MIT License (https://opensource.org/licenses/MIT). A copy of MIT License is included in this repository.

Attribution

The following 3rd-party software components may be used by or distributed with route53-dynamic-dns: https://app.fossa.io/reports/f5377d5f-557e-4e21-8bfa-93a27ea6e540

FOSSA Status

About

Update AWS Route53 hosted zone with current public IP address. Alternative to Dynamic DNS services such as Dyn, No-IP, etc

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 88.6%
  • Dockerfile 10.4%
  • Shell 1.0%