Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Dynamically update Cloudflare DNS record for a Ngrok tunnel

License

Notifications You must be signed in to change notification settings

voidlesity/ngrok-dynamic-dns

Repository files navigation

IMPORTANT !!

Ngrok has modified their free tier, and now you are limited to 1GB of traffic per month through their tunnels. Therefore, if you intend to use this service daily, you might run out of the allocatted data before the month ends.

Dynamic DNS for TCP Ngrok Tunnel using Cloudflare

This Python program allows you to dynamically update your Cloudflare DNS records to point to a TCP Ngrok tunnel. It's especially handy for applications where you want to expose a local server to the internet, but the IP might change (for instance, if using a service like Ngrok). The program ensures that the DNS record is always updated with the latest Ngrok tunnel information.

How to Install

You can download the latest version of the program here.

Alternatively, if you prefer to set things up yourself check the How to Build It Yourself Tab.

How to Use

  1. Generate a new SRV record that will act as your Dynamic DNS.
  2. Run NgrokDynamicDNS which should open up a configuration window. If not run NgrokDynamicDNS config.
  3. Fill in the appropriate API Key, Zone ID, Record ID, and Ngrok Api URL.
  4. Once you have saved your configuration, the program will begin to run in the background.

If you want to stop it you will have to close it through the task manager.

Generate SRV record

  1. On the left side of cloudflare after you selected a Domain you can click on DNS.

  2. Then click "Add record" enter:

    Minecraft Server Example
    
        "Type" = SRV
        "Name" = "your Subdomain for example mc"
        "Service" = "_minecraft"
        "Protocol" = TCP
        "TTL" = Auto
        "Priority" = 5
        "Weight" = 1
    
        and for "Port" and "Target" you can enter a place holder.
    
  3. Save.

How to generate an Api Key

  1. Go to cloudflare and log in.
  2. In the top right click on My Profile then click on Api Keys on the left side.
  3. Click Create Key and select "Edit zone DNS" template.
  4. Under "Zone Resources" you can change to one specific zone or all zones, I recommend using all zones.
  5. Click on "Continue to summary" -> "Create Key" and then copy it.

How to get Zone ID

  1. Again go to cloudflare and log in.
  2. Click on your Domain and on the right side you will see a list of Infos regarding your Domain
  3. Look under "API" -> "Zone ID" and copy it.

How to get Record ID

If you have done step 2. just click on the bottom left of the configuration window where it says "Get Records". Then select the one you just made.

How to get Ngrok Api URL

If you are running this program on the same computer as your Ngrok tunnel the default path would be:

http://127.0.0.1:4040/api/tunnels

if not you are probably advanced enough to find it yourself just make sure to also add /api/tunnels to the end of the url

What It Does

Here's a rundown of what this program does:

  1. Interacts with the Cloudflare API to update DNS records, specifically SRV records.
  2. Periodically checks your Ngrok TCP tunnel's current external address.
  3. Updates the DNS record whenever there's a change in the Ngrok tunnel information.

How to Build It Yourself

If you'd like to tweak, customize or just play around with the source code, here's how you can get started:

  1. Clone this repository and run the createEnvironment.bat.
  2. Change up the code if you'd like.
  3. Then run the build.bat you can also edit it if you want for example add an icon.
  4. The resultant executable will be located in the dist folder.