Simple script to quickly implement DDNS based on CloudFlare.
简体中文 [English]
Installation Methods:
- Auto (ddns/whoiam);
- Manual (ddns/whoiam);
- Source Code Installation (ddns/whoiam); This won’t be explained here—those who understand code will figure it out at a glance.
- Docker (ddns/whoiam);
- Cloudflare Workers (whoiam);
🧨Tip: Whether you install it automatically or manually, please modify the configuration
config.json
yourself! If you use other IP acquisition services, please modify the source code yourself (if you don't need authorization, you can try not to modify the source code)
- ddns_client
curl -sSL https://github.com/dingdangdog/cloudflare_ddns/raw/main/script/update_ddns.sh | bash
Modify the config_demo.json
and run ddns_client
.
- whoiam_server
curl -sSL https://github.com/dingdangdog/cloudflare_ddns/raw/main/script/update_whoiam.sh | bash
Modify the config_demo.json
and run whoiam_server
.
- Download
ddns_client
orwhoiam_server
from Last Release, or Package ddns_client / Package whoiam_server by yourself; - Download ddns_client [config_demo.json](./ddns/config demo.json) or whoiam_server config_demo.json to your device, rename it to
config.json
, and then edit the configuration information。 - Run
ddns_client
orwhoiam_server
。
You can read the contents of the corresponding docker-compose.yaml files and confidently choose whether to use docker-compose or docker run for deployment. This won’t be explained in detail here—please take the time to learn Docker on your own!
- Create a Worker in the Cloudflare console;
- Copy all the code from whoiam.js and paste it into the Worker;
- Start the Worker;
- Configure the environment variable CLIENT_KEYS—you can configure multiple keys, separated by commas (,);
- After configuration, click Deploy to redeploy the Worker.
Find a way to get the real IP
, and after getting the IP
, call the Cloudflare API
to modify the DNS
record.
Tip: In the
Windows
development environment, please execute the command in theCMD
terminal command line, not inPowerShell
, otherwise the packaged result may not be executed normally
# Packaging Linux binary files in Windows development environment
cd ddns
SET GOOS=linux
SET GOARCH=amd64
go build -o ddns_client ddns.go
{
"CLOUDFLARE": {
"CF_API_TOKEN": "xx", // Please get your Cloudflare configuration
"CF_ZONE_ID": "xxx", // Please get your Cloudflare configuration
"CF_RECORD_ID": "xxx", // Please get your Cloudflare configuration
"DNS_TYPE": "A",
"DNS_DOMAIN_NAME": "xxx.com", // DNS domain name to be set
"DNS_DOMAIN_CONTENT": "xxx.com", // Temporarily unused
"DNS_TTL": 1, // Fill in 1 to use the default value of cloudflare
"DNS_PROXIED": false
},
"WHOIAM_API_URL": "http://xxx.com/whoiam", // Interface to obtain the real public IP
"WHOIAM_CLIENT_ID": 0, // Whoisme interface authorization id
"WHOIAM_CLIENT_KEY": "Test_Cilent_Key", // Whoisme interface authorization key
"MODE": "development",
"INTERVAL": 180
}
A simple service that gets the client's public IP and returns it.
deploy on the server,
ddns client
requests this interface of the server, obtains the client's real IP and returns it.
cd whoiam
go run whoiam.go
Tip: In the
Windows
development environment, please execute the command in theCMD
terminal command line, not inPowerShell
, otherwise the packaged result may not be executed normally
# Packaging Linux binary files in Windows development environment
cd whoiam
SET GOOS=linux
SET GOARCH=amd64
go build -o whoiam_server whoiam.go
Notice:
- Ensure the interface returns only the IP address! If you want to use other formats, please modify the code yourself!
- If it returns an IPv6 address, it cannot be used!
Interface URL | Usage Restrictions | Remarks |
---|---|---|
https://api.ipify.org | No restrictions, free | Simple and easy to use |
https://icanhazip.com | No restrictions, free | Operated by Cloudflare, returns plain text |
https://api.seeip.org | No restrictions, free | Supports IPv4/IPv6, open source |