ts-ddns is a DDNS service based on cloudflare.
It helps you to detect the changes of public IP address and update new IP to the records on cloudflare in time to ensure your domain is always pointed to your public IP.
To use ts-ddns, following the steps below (based on ubuntu 22.04):
- Go to Cloudflare dashboard
- Click
Add a siteto add an existing domain to cloudflare zones, or skip this step if you already have a zone added - Click an existing zone, for example,
example.com, to enter the overview of this zone - Click
DNS-Recordsto enter the DNS Records panel - Click
Add recordto add a record for our DDNS service. Let's useddns.example.comas an example- Select
AinTypelist - In
Name (required), enter the prefix of your subdomain, we useddnshere - In
IPv4 address (required), enter any IPv4 address value, such as12.34.56.78, it will be overwrote by ts-ddns - Switch off the
Proxy - In
TTL, select1 min - Click
Save - Now, we have successfully created a record for the subdomain
ddns.example.comunder the zoneexample.com
- Select
- Go to Cloudflare API Tokens page.
- Click
Create Token - Create Custom Token
- In
Create Custom Tokenpage, enter the name of the token - In
Permissionssection, AddZone:Zone:ReadandZone:DNS:Edit - Create Token
- Now you get a 40-byte-token like
9nLuODKqFleQF71PZOikRrjzgQzJft2AbYQkdJfG
curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -sudo apt install nodejs build-essential -ycorepack enable
- Clone ts-ddns:
git clone https://github.com/Nukami/ts-ddns.git - Assuming that we have cloned ts-ddns to
/git/ts-ddns:cd /git/ts-ddns yarn install && yarn ncc- Now we will get
/git/ts-ddns/dist/index.jsand/git/ts-ddns/dist/config.yml - Edit
config.yml, for more information, go to Configuration - Launch ts-ddns:
node /git/ts-ddns/dist/index.js
ts-ddns can be launched by many ways.
We could also simply append node /git/ts-ddns/dist/index.js & to the end of /etc/rc.local, so that ts-ddns will automatically start on everytime we reboot.
But here, I would suggest using PM2, which can automatically start ts-ddns every time the system runs, and also automatically restart it in case of unexpected crashes
- Install PM2:
sudo npm install pm2 -g - Create PM2 startup script:
sudo pm2 startup- You need to enable the startup script manually:
sudo systemctl enable pm2-root - You also have to start pm2 service:
sudo systemctl start pm2-root
- You need to enable the startup script manually:
- Start ts-ddns:
pm2 start /git/ts-ddns/dist/index.js --name ts-ddns --watch - Update your app list:
pm2 save
The configuration file config.yml should be placed under the same directory as index.js
It should looks like:
# Create from https://dash.cloudflare.com/profile/api-tokens
token: long-long-long-long-long-long-long-token
# Domains and names of their A records you want to update
records:
example-a.com:
# example-a.com
- "@"
# ddns.example-a.com
- ddns
example-b.com:
# a.example-b.com
- a
# c.example-b.com
- c
# Interval (in seconds) between two ip checking
interval: 120
# DISABLE, ERROR, WARN, INFO, DEBUG
log_level: INFO
# Path to the dir of logs files
logs: /var/log/ts-ddnsA 40-byte-string to access the api of cloudflare. See 2. Create API Tokens
ts-ddns supports multiple records of multiple zones.
In records field, you could specify numbers of zones(domain names), and numbers of prefixes of their subdomain.
You should list each domain name as a key, and its value should be the list of prefixes of subdomains
ddns.example.com as example:
records:
example.com:
- "ddns"Specify how many seconds between two IP checks. Default to 120 seconds.
There are 5 levels of log:
- DISABLE - Disable any log
- ERROR - Record error only
- WARN - Record error and warning messages
- INFO - Record error, warning and information messages
- DEBUG - Record error, warning, information and debug messages. Also dump objects of HTTP requests for debugging
The directory where logs files should be outputed
Although ts-ddns can create directories automatically, if you encounter "permission denied" errors, you may need to create the directory manually.
Leave it empty or delete this field to disable the output of logs files
- Cloudflare
- We obtained FREE and powerful domain name resolving service from Cloudflare
- IP Address Lookup - IP.SB
- We detect the changes of our public IP address by requesting ip.sb periodically
- ipify
- We use ipify as a backup when we are unable to access ip.sb in somehow