Skip to content

A TypeScript Express application that dynamically updates DNS records on Cloudflare with the current public IP address.

License

Notifications You must be signed in to change notification settings

rdp-datacenter/ip-update

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cloudflare Dynamic DNS Updater

This is a TypeScript Express application that dynamically updates DNS records on Cloudflare with the current public IP address of the server. It uses the Cloudflare API to perform the updates and includes authentication via API key.

Features

  • Fetches the current public IP address using the ipify API
  • Updates specified DNS records in Cloudflare API with the current IP address
  • Secured with an API key to prevent unauthorized access
  • Includes unique request IDs for all API responses
  • Provides human-friendly JSON responses with automatic pretty-printing
  • Clear separation between public and protected endpoints

Installation

Using npm

npm install cloudflare-dyndns-updater

From GitHub

  1. Clone the repository:
    git clone https://github.com/rdp-datacenter/ip-update.git
  2. Navigate to the project directory:
    cd ip-update
  3. Install dependencies:
    npm install
  4. Build the TypeScript files:
    npm run build

Getting Started

Prerequisites

  • Node.js (v14 or higher recommended)
  • npm or yarn
  • A Cloudflare account with API credentials
  • An .env file with the necessary configuration values

Environment Variables

Create a .env file in the root directory with the following variables:

  • PORT: Port number for the Express server (default is 5555)
  • CF_DNS: Comma-separated list of Cloudflare DNS record IDs that you want to update
  • CF_ZONE: Cloudflare Zone ID where DNS records are managed
  • CF_MAIL: Cloudflare Email address associated with the account
  • CF_AUTH: Cloudflare API token for authentication
  • RDP_API_KEY: Your own API key used to authenticate requests to this service

Example .env file:

RDP_API_KEY=your_own_generated_key
CF_DNS=record1,record2,record3
CF_ZONE=your_cloudflare_zone_id
CF_MAIL=your_cloudflare_email
CF_AUTH=your_cloudflare_auth_token
PORT=3000

Usage

As a standalone application

  1. Start the server:
    npm start
  2. Access the service information by sending a GET request to the root endpoint:
    curl -X GET http://localhost:5555/
  3. Update the DNS records by sending a GET request to the update endpoint with your API key:
    curl -X GET http://localhost:5555/update?api_key=<your-secure-api-key>
    Or using the header method:
    curl -X GET -H "rdp-key: <your-secure-api-key>" http://localhost:5555/update

As a module in your Node.js project

const { app } = require('cloudflare-dyndns-updater');
// Or with ES Modules
// import { app } from 'cloudflare-dyndns-updater';

// You can now use the Express app instance
const port = process.env.PORT || 3000;
app.listen(port, () => {
  console.log(`DNS updater running on port ${port}`);
});

API Endpoints

GET / (Public)

Returns information about the service and available endpoints.

Response:

{
  "name": "RDP DNS Updater",
  "version": "1.0.0",
  "request_id": "9ABCDD4CC53F2BC1-RDP",
  "endpoints": [
    { "path": "/update", "method": "GET", "description": "Update DNS records with current IP (requires API key)" },
    { "path": "/health", "method": "GET", "description": "Service health check (no auth required)" },
    { "path": "/update-all", "method": "GET", "description": "Update all DNS records (requires API key)" }
  ],
  "status": "operational"
}

GET /update (Protected)

Updates the DNS records with the current public IP address. Requires an API key.

Authentication:

  • Header: rdp-key: <your-api-key>
  • Or Query Parameter: api_key=<your-api-key>

Response (Success):

{
  "status": "success",
  "ip": "76.76.21.21",
  "request_id": "9ABCDD4CC53F2BC1-RDP",
  "records": [
    {
      "id": "record1",
      "name": "dns.rdpdatacenter.in",
      "success": true,
      "status": 200
    }
  ]
}

Response (Error):

{
  "status": "failed",
  "request_id": "9ABCDD4CC53F2BC1-RDP",
  "error": "Error message details"
}

GET /health (Public)

Checks if the service is running properly.

Response:

{
  "status": "healthy",
  "request_id": "9ABCDD4CC53F2BC1-RDP",
  "timestamp": "2025-04-26T12:34:56.789Z"
}

GET /update-all (Protected)

Updates all configured DNS records. Requires an API key.

Authentication:

  • Same as /update endpoint

Response:

{
  "status": "success",
  "request_id": "9ABCDD4CC53F2BC1-RDP",
  "message": "All DNS records updated successfully"
}

Request IDs

Every API response includes a unique request ID in both the response headers (RDP-Request-ID) and the response body (request_id). These IDs can be used for debugging and tracking purposes.

Development

For local development with automatic reloading:

npm run dev

Docker

You can run the application in a Docker container using either Docker directly or Docker Compose.

Using Docker Compose (Recommended)

A docker-compose.yml file is provided for easy deployment:

# Build and start the container
docker-compose up -d

# View logs
docker-compose logs -f

# Stop the container
docker-compose down

Using Docker Directly

# Build the Docker image
docker build -t ip-update .

# Run the container
docker run -p 5555:5555 --env-file .env ip-update

Docker Configuration

The Docker setup includes:

  • Node.js slim image for a lightweight container
  • Proper caching of npm dependencies
  • Production mode settings
  • Health checks via the /health endpoint
  • Volume mounting for logs
  • Automatic container restart

Vercel Deployment

This project is also configured for deployment on Vercel. The vercel.json file includes the necessary configuration.

Contributing

Feel free to submit issues, feature requests, or pull requests. Contributions are welcome!

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

For any questions or issues, please contact [email protected].

About

A TypeScript Express application that dynamically updates DNS records on Cloudflare with the current public IP address.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •