Skip to content

Commit dbeb691

Browse files
committed
feat: support multiple providers
1 parent cb96d86 commit dbeb691

File tree

10 files changed

+817
-28
lines changed

10 files changed

+817
-28
lines changed

MULTI_PROVIDER.md

Lines changed: 222 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,222 @@
1+
# Multi-Provider Configuration Guide
2+
3+
GoDNS now supports configuring multiple DNS providers simultaneously, allowing you to manage domains across different DNS services from a single GoDNS instance.
4+
5+
## Features
6+
7+
- **Multi-Provider Support**: Configure multiple DNS providers (Cloudflare, DNSPod, DigitalOcean, etc.) in one config file
8+
- **Per-Domain Provider**: Specify different providers for different domains
9+
- **Full Backward Compatibility**: Existing single-provider configurations continue to work unchanged
10+
- **Mixed Configuration**: Combine legacy global provider with new per-domain providers
11+
- **Provider-Specific Credentials**: Each provider can have its own authentication credentials
12+
13+
## Configuration Options
14+
15+
### Option 1: Multi-Provider Configuration
16+
17+
Configure multiple providers with per-domain assignment:
18+
19+
```json
20+
{
21+
"providers": {
22+
"cloudflare": {
23+
"email": "[email protected]",
24+
"password": "your-cloudflare-api-token"
25+
},
26+
"dnspod": {
27+
"login_token": "your-dnspod-token"
28+
},
29+
"digitalocean": {
30+
"password": "your-digitalocean-api-token"
31+
}
32+
},
33+
"domains": [
34+
{
35+
"domain_name": "example.com",
36+
"sub_domains": ["www", "api"],
37+
"provider": "cloudflare"
38+
},
39+
{
40+
"domain_name": "mysite.net",
41+
"sub_domains": ["mail", "ftp"],
42+
"provider": "dnspod"
43+
}
44+
]
45+
}
46+
```
47+
48+
### Option 2: Legacy Single-Provider (Backward Compatible)
49+
50+
Existing configurations continue to work unchanged:
51+
52+
```json
53+
{
54+
"provider": "DNSPod",
55+
"login_token": "your-dnspod-token",
56+
"domains": [
57+
{
58+
"domain_name": "example.com",
59+
"sub_domains": ["www", "test"]
60+
}
61+
]
62+
}
63+
```
64+
65+
### Option 3: Mixed Configuration
66+
67+
Combine global provider with specific per-domain providers:
68+
69+
```json
70+
{
71+
"provider": "DNSPod",
72+
"login_token": "your-dnspod-token",
73+
"providers": {
74+
"cloudflare": {
75+
"email": "[email protected]",
76+
"password": "your-cloudflare-api-token"
77+
}
78+
},
79+
"domains": [
80+
{
81+
"domain_name": "oldsite.com",
82+
"sub_domains": ["www", "mail"]
83+
},
84+
{
85+
"domain_name": "newsite.com",
86+
"sub_domains": ["www", "api"],
87+
"provider": "cloudflare"
88+
}
89+
]
90+
}
91+
```
92+
93+
## Provider Configuration Fields
94+
95+
Each provider in the `providers` section supports these common fields:
96+
97+
- `email`: Email address for authentication (Cloudflare, etc.)
98+
- `password`: API token or password
99+
- `password_file`: Path to file containing password/token
100+
- `login_token`: Login token for token-based auth (DNSPod, etc.)
101+
- `login_token_file`: Path to file containing login token
102+
- `app_key`: Application key (provider-specific)
103+
- `app_secret`: Application secret (provider-specific)
104+
- `consumer_key`: Consumer key (provider-specific)
105+
106+
## Domain Configuration
107+
108+
Domains support an optional `provider` field:
109+
110+
```json
111+
{
112+
"domain_name": "example.com",
113+
"sub_domains": ["www", "api", "@"],
114+
"provider": "cloudflare"
115+
}
116+
```
117+
118+
If `provider` is omitted, the domain uses the global `provider` setting.
119+
120+
## Supported Providers
121+
122+
All existing providers are supported in multi-provider mode:
123+
124+
- Cloudflare
125+
- DNSPod
126+
- DigitalOcean
127+
- Alidns
128+
- Google
129+
- HE (Hurricane Electric)
130+
- Dreamhost
131+
- Duck DNS
132+
- NoIP
133+
- Scaleway
134+
- DynV6
135+
- Linode
136+
- Strato
137+
- Loopiase
138+
- Infomaniak
139+
- Hetzner
140+
- OVH
141+
- Dynu
142+
- IONOS
143+
- TransIP
144+
145+
## Migration Guide
146+
147+
### From Single to Multi-Provider
148+
149+
1. **Keep existing config working**: No changes needed for current setups
150+
2. **Add new providers gradually**:
151+
```json
152+
{
153+
"provider": "DNSPod", // Keep existing
154+
"login_token": "old-token",
155+
"providers": { // Add new providers
156+
"cloudflare": {
157+
"email": "[email protected]",
158+
"password": "cf-token"
159+
}
160+
},
161+
"domains": [
162+
{
163+
"domain_name": "old-domain.com",
164+
"sub_domains": ["www"] // Uses DNSPod (global provider)
165+
},
166+
{
167+
"domain_name": "new-domain.com",
168+
"sub_domains": ["www"],
169+
"provider": "cloudflare" // Uses Cloudflare
170+
}
171+
]
172+
}
173+
```
174+
175+
3. **Complete migration**: Remove global provider once all domains specify providers
176+
177+
## Configuration Examples
178+
179+
See the example configuration files:
180+
181+
- `configs/config_multi_sample.json` - Full multi-provider setup
182+
- `configs/config_multi_sample.yaml` - YAML version of multi-provider setup
183+
- `configs/config_legacy_compatible.json` - Shows backward compatibility
184+
- `configs/config_mixed_sample.json` - Mixed legacy + new provider configuration
185+
186+
## Logging and Notifications
187+
188+
Multi-provider configurations include provider information in log messages and notifications:
189+
190+
```
191+
INFO [2024-01-01T12:00:00Z] Initialized provider: cloudflare
192+
INFO [2024-01-01T12:00:00Z] Initialized provider: dnspod
193+
INFO [2024-01-01T12:00:00Z] [ www, api ] of example.com (via cloudflare)
194+
```
195+
196+
## Benefits
197+
198+
1. **Consolidation**: Manage multiple DNS providers from one GoDNS instance
199+
2. **Flexibility**: Use the best provider for each domain
200+
3. **Redundancy**: Distribute domains across providers for resilience
201+
4. **Migration**: Gradually move domains between providers
202+
5. **Cost Optimization**: Use different providers based on pricing/features
203+
6. **Compliance**: Meet requirements for geographic distribution
204+
205+
## Troubleshooting
206+
207+
### Provider Not Found Error
208+
```
209+
ERROR provider 'cloudflare' not found for domain example.com
210+
```
211+
**Solution**: Ensure the provider is configured in the `providers` section.
212+
213+
### Authentication Failures
214+
```
215+
ERROR failed to create provider cloudflare: authentication failed
216+
```
217+
**Solution**: Verify credentials in the provider configuration section.
218+
219+
### Mixed Configuration Issues
220+
If a domain doesn't specify a `provider` field, it will use the global `provider`. Ensure:
221+
1. Global `provider` is set when using mixed configuration
222+
2. All required credentials are provided for the global provider

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
- [Usage](#usage)
3232
- [Configuration](#configuration)
3333
- [Overview](#overview)
34+
- [Multi-Provider Support](#multi-provider-support)
3435
- [Configuration file format](#configuration-file-format)
3536
- [Dynamic loading of configuration](#dynamic-loading-of-configuration)
3637
- [Configuration properties](#configuration-properties)
@@ -197,6 +198,17 @@ Usage of ./godns:
197198
- Configure a notification medium (e.g. SMTP to receive emails) to get notified when your IP address changes
198199
- Place the file in the same directory of GoDNS or use the `-c=path/to/your/file.json` option
199200

201+
### Multi-Provider Support
202+
203+
🆕 **GoDNS now supports multiple DNS providers simultaneously!**
204+
205+
You can now configure domains from different DNS providers in a single configuration file, allowing you to:
206+
- Manage domains across multiple DNS services (Cloudflare, DNSPod, DigitalOcean, etc.)
207+
- Use provider-specific credentials for each service
208+
- Maintain full backward compatibility with existing single-provider configurations
209+
210+
📖 **[View the complete Multi-Provider Configuration Guide](MULTI_PROVIDER.md)** for detailed setup instructions and examples.
211+
200212
### Configuration file format
201213

202214
GoDNS supports 2 different configuration file formats:
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
{
2+
"comment": "Legacy configuration - backward compatible with existing single-provider setups",
3+
4+
"provider": "DNSPod",
5+
"password": "",
6+
"login_token": "your-dnspod-token",
7+
8+
"domains": [
9+
{
10+
"domain_name": "example.com",
11+
"sub_domains": ["www", "test"]
12+
},
13+
{
14+
"domain_name": "example2.com",
15+
"sub_domains": ["www", "test", "@"]
16+
}
17+
],
18+
19+
"ip_urls": [
20+
"https://api4.ipify.org",
21+
"https://myip.biturl.top",
22+
"https://ipecho.net/plain",
23+
"https://api-ipv4.ip.sb/ip",
24+
"https://ip2location.io/ip",
25+
"https://ipinfo.io/ip"
26+
],
27+
28+
"ipv6_urls": [
29+
"https://api6.ipify.org",
30+
"https://api-ipv6.ip.sb/ip",
31+
"https://ip2location.io/ip",
32+
"https://v6.ipinfo.io/ip"
33+
],
34+
35+
"ip_type": "IPv4",
36+
"interval": 300,
37+
"resolver": "8.8.8.8",
38+
"user_agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/38.0.2125.111 Safari/537.36",
39+
"ip_interface": "eth0",
40+
41+
"mikrotik": {
42+
"enabled": false,
43+
"addr": "http://192.168.88.1:81",
44+
"username": "admin",
45+
"password": "",
46+
"interface": "pppoe-out"
47+
},
48+
49+
"web_panel": {
50+
"enabled": true,
51+
"addr": "0.0.0.0:9000",
52+
"username": "admin",
53+
"password": "123456"
54+
},
55+
56+
"socks5_proxy": "",
57+
"use_proxy": false,
58+
"debug_info": false,
59+
"proxied": false,
60+
"skip_ssl_verify": false,
61+
62+
"notify": {
63+
"telegram": {
64+
"enabled": false,
65+
"bot_api_key": "",
66+
"chat_id": "",
67+
"message_template": ""
68+
},
69+
"mail": {
70+
"enabled": false,
71+
"smtp_server": "",
72+
"smtp_username": "",
73+
"smtp_password": "",
74+
"smtp_port": 25,
75+
"send_from": "",
76+
"send_to": ""
77+
}
78+
},
79+
80+
"webhook": {
81+
"enabled": false,
82+
"url": "http://localhost:5000/api/v1/send",
83+
"request_body": "{ \"domain\": \"{{.Domain}}\", \"ip\": \"{{.CurrentIP}}\", \"ip_type\": \"{{.IPType}}\" }"
84+
}
85+
}

configs/config_mixed_sample.json

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
{
2+
"comment": "Mixed configuration example - demonstrates transition from single to multi-provider",
3+
"comment2": "Some domains use specific providers while others fall back to the global provider",
4+
5+
"provider": "DNSPod",
6+
"login_token": "your-dnspod-token",
7+
8+
"providers": {
9+
"cloudflare": {
10+
"email": "[email protected]",
11+
"password": "your-cloudflare-api-token"
12+
}
13+
},
14+
15+
"domains": [
16+
{
17+
"domain_name": "oldsite.com",
18+
"sub_domains": ["www", "mail"]
19+
},
20+
{
21+
"domain_name": "newsite.com",
22+
"sub_domains": ["www", "api", "@"],
23+
"provider": "cloudflare"
24+
},
25+
{
26+
"domain_name": "another-old.net",
27+
"sub_domains": ["ftp", "@"]
28+
}
29+
],
30+
31+
"ip_urls": [
32+
"https://api4.ipify.org",
33+
"https://myip.biturl.top",
34+
"https://ipecho.net/plain"
35+
],
36+
37+
"ip_type": "IPv4",
38+
"interval": 300,
39+
"resolver": "8.8.8.8",
40+
41+
"web_panel": {
42+
"enabled": true,
43+
"addr": "0.0.0.0:9000",
44+
"username": "admin",
45+
"password": "123456"
46+
},
47+
48+
"use_proxy": false,
49+
"debug_info": true,
50+
"skip_ssl_verify": false,
51+
52+
"notify": {
53+
"telegram": {
54+
"enabled": false
55+
}
56+
}
57+
}

0 commit comments

Comments
 (0)