1
0
digitalocean-dynamic-dns-ip/README.md

90 lines
3.8 KiB
Markdown
Raw Normal View History

# DIGITAL OCEAN DYNAMIC IP API CLIENT
A simple script in Go language to automatically update Digital ocean DNS records if you have a dynamic IP. Since it can be compiled on any platform, you can use it along with raspberrypi etc.
2019-09-26 10:45:03 -07:00
To find your Dynamic IP, this program will call out to https://ipv4bot.whatismyipaddress.com for ipv4 addresses and https://ipv6bot.whatismyipaddress.com for ipv6 addresses. This is to support dual-stack environments. (These URLs can be customized; see Usage, below.)
## Requirements
Requires Git, Go 1.8+, and https://github.com/mitchellh/go-homedir for building.
2017-11-12 05:46:49 -08:00
Requires that the record already exists in DigitalOcean's DNS so that it can be updated.
(manually find your IP and add it to DO's DNS it will later be updated)
Requires a Digital Ocean API key that can be created at https://cloud.digitalocean.com/account/api/tokens.
## Building
You first need to install the "homedir" module if you aren't using it in another project. To install the module, run `go get github.com/mitchellh/go-homedir`
Once the module is fetched, you should be able to compile the program using `go build`
## Usage
```bash
2019-09-26 10:45:03 -07:00
# clone the repo in ~/go/src/github.com/anaganisk:
git clone https://github.com/anaganisk/digitalocean-dynamic-dns-ip.git
```
2019-09-26 10:45:03 -07:00
Create a file `.digitalocean-dynamic-ip.json` (dot prefix to hide the file) and place it in your home directory. Add the following JSON (or refer to the sample configuration file, `digitalocean-dynamic-ip.sample.json`):
```json
{
"apikey": "samplekeydasjkdhaskjdhrwofihsamplekey",
"doPageSize": 20,
2019-07-20 20:26:15 -07:00
"useIPv4": true,
"useIPv6": false,
2019-07-20 22:13:34 -07:00
"allowIPv4InIPv6": false,
2019-09-26 10:45:03 -07:00
"ipv4CheckUrl": "https://ipv4bot.whatismyipaddress.com",
2017-11-12 05:46:49 -08:00
"domains": [
{
2017-11-12 05:46:49 -08:00
"domain": "example.com",
"records": [
{
"name": "subdomainOrRecord",
"type": "A"
}
]
},
{
"domain": "example2.com",
"records": [
{
"name": "subdomainOrRecord2",
"type": "A",
"TTL": 30
2017-11-12 05:46:49 -08:00
}
]
}
]
}
```
2019-09-26 10:45:03 -07:00
The TTL can optionally be updated if passed in the configuration. Digital Ocean has a minimum TTL of 30 seconds. The `type` and the `name` must match existing records in the Digital Ocean DNS configuration. Only `types` of `A` and `AAAA` allowed at the moment.
2019-07-20 22:13:34 -07:00
If you want to reduce the number of calls made to the digital ocean API and have more than 20 DNS records in your domain, you can adjust the `doPageSize` parameter. By default, Digital Ocean returns 20 records per page. Digital Ocean has a max page size of 200 items.
2019-07-20 20:26:15 -07:00
By default, the configuration checks both IPv4 and IPv6 addresses assuming your provider set up your connection as dual stack. If you know you only have ipv4 or ipv6 you can disable using one or the other in the config. To disable one or the other, set the `useIPv4` or `useIPv6` settings to `false`. If the options aren't present, or are set to `null`, then the configuration assumes a value of `true`.
2019-07-20 22:13:34 -07:00
The `allowIPv4InIPv6` configuration option will allow adding an IPv4 address to be used in a AAAA record for IPv6 lookups.
2019-09-26 10:45:03 -07:00
The `ipv4CheckUrl` and `ipv6CheckUrl` configuration settings are optional. If set, they must be URLs which respond to a GET request, with a plaintext response containing only your IP address. If unset, they default to `https://ipv_bot.whatismyipaddress.com`.
```bash
2019-09-26 10:45:03 -07:00
# after running `go build digitalocean-dynamic-ip.go`, run:
./digitalocean-dynamic-ip
```
Optionally, you can create the configuration file with any name wherever you want, and pass it as a command line argument:
2019-09-26 10:45:03 -07:00
2019-08-05 07:07:13 -07:00
```bash
2019-09-26 10:45:03 -07:00
#run:
2019-08-05 07:07:13 -07:00
./digitalocean-dynamic-ip /path/to/my/config.json
```
You can either set this to run periodically with a cronjob or use your own method.
2019-09-26 10:45:03 -07:00
```bash
2019-09-26 10:45:03 -07:00
# run `crontab -e` to edit your crontab
# sample cron job task
# m h dom mon dow command
*/5 * * * * /home/user/digitalocean-dynamic-dns-ip/digitalocean-dynamic-ip
```