├── .gitignore └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | .idea 2 | log 3 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | What 2 | ====== 3 | These steps will install ddclient on your Ubuntu server and allow it to update any Cloudflare domains you want with your current dynamic IP address. The computer on which you install this script should be one that remains at the same location as the dynamic IP you'd like to link. 4 | 5 | Why 6 | ====== 7 | Let's say you want to host a VPN server, a website, your files or anything else at home. Unless you have a static IP address, which in some cases you can't get without signing up for a business account, you'll need a way to associate your dynamic IP address with a domain name so your service doesn't get interrupted when your assigned public IP changes. 8 | 9 | Which Technologies 10 | ====== 11 | This guide focuses on installing [ddclient](https://github.com/wimpunk/ddclient) on Ubuntu (I used 16.04 server) and integrating it with Cloudflare. There are many other installation methods, so check out the ddclient repo for a full list. 12 | 13 | How 14 | ====== 15 | Ssh into your Ubuntu machine and become the root user: 16 | ```bash 17 | ssh username@ipaddress.of.machine -p port_you_set_default_is_22 18 | sudo su 19 | ``` 20 | Next clone/download the ddclient repo from Github. I used the `/tmp` directory, but you can use whatever you want. Move to that directory: 21 | ```bash 22 | cd /tmp 23 | ``` 24 | Clone the repo into the directory you chose: 25 | ```bash 26 | git clone https://github.com/ddclient/ddclient.git 27 | ``` 28 | Next enter the new ddclient directory and copy ddclient to `/usr/sbin`: 29 | ```bash 30 | cd /tmp/ddclient 31 | cp ddclient /usr/sbin/ 32 | ``` 33 | Make a couple directories that are missing: 34 | ```bash 35 | mkdir /etc/ddclient 36 | mkdir /var/cache/ddclient 37 | ``` 38 | Once those directories are made, copy the default config to use as your starting place: 39 | ```bash 40 | cp sample-etc_ddclient.conf /etc/ddclient/ddclient.conf 41 | ``` 42 | Open that file for editing: 43 | ```bash 44 | vim /etc/ddclient/ddclient.conf 45 | ``` 46 | Once in Vim, you want to hit `i` to enter insert mode, at which point you'll be able to enter text. The first thing to do is to remove the `#` at the beginning of this line: 47 | ``` 48 | use=web, web=checkip.dyndns.org/, web-skip='IP Address’ 49 | ``` 50 | Now search for the Cloudflare section by hitting the escape key to exit insert mode and then typing a `/` and then `cloudflare` an hitting enter. That should bring you to the section. Once there, set it up by first removing the `#` from beginning of each line and then changing everything that starts with a `$` below to your personal details: 51 | ``` 52 | protocol=cloudflare, \ 53 | zone=$domain.tld, \ 54 | login=$your@cloudflare.login, \ 55 | password=$your_api_key \ 56 | ttl=1 \ 57 | $domain.tld,$subdomain1.domain.tld,$subdomain2.domain.tld 58 | ``` 59 | A couple notes about the lines above: make sure the password line does not end in a comma. You can update as many domains and subdomains as you'd like by placing them on the last line of the config block but remember they will all be set to the same IP. 60 | 61 | Hit escape again to exit insert mode and hit `:` and type `wq` then hit enter to save and exit vim. 62 | 63 | Now you're ready to test your setup with the following command: 64 | ```bash 65 | ddclient -daemon=0 -debug -verbose -noquiet 66 | ``` 67 | It may (and probably will) fail and that's just fine; there are a variety of errors that I discuss at the bottom of this readme. Each time you correct an error, run the above command to test whether it corrected that specific error. 68 | 69 | Once everything is working, perform one final test by changing one of your Cloudflare DNS entries of a domain you want associated with your dynamic IP to something that isn't your dynamic ip, then run the test command above and verify that it did, in fact, change it back. Once you see that you know you're good. 70 | 71 | Now you're ready to set ddclient to run at startup and launch it on boot. If you've changed directories, go back to where you initially cloned the ddclient repo, for me that was `/tmp/ddclient` by entering: 72 | ```bash 73 | cd /tmp 74 | ``` 75 | Copy the Ubuntu launch script to your `/etc/init.d` folder and enable it on boot: 76 | ```bash 77 | cp sample-etc_rc.d_init.d_ddclient.ubuntu /etc/init.d/ddclient 78 | update-rc.d ddclient 79 | ``` 80 | Finally, start the service manually the first time: 81 | ```bash 82 | service ddclient start 83 | ``` 84 | In order to double check that everything is set up correctly, run `ddclient -query` and make sure that this line is correct: `use=web, web=dnspark address is your.public.ip`. In order to access the query mode, press control+c. After the script has run a couple times you'll also want to check the "mail" that the script is creating because there may be one more issue. Open the mail by running: 85 | ```bash 86 | sudo vim /etc/mail/root 87 | ``` 88 | If you see an error that looks like this: 89 | ```bash 90 | WARNING: file /var/cache/ddclient/ddclient.cache, line 3: Invalid Value for keyword 'ip' = '' 91 | ``` 92 | you may need to update the version of ddclient. The error has been fixed in more recent versions, but [this post](http://askubuntu.com/questions/64219/why-is-ddclient-giving-me-an-invalid-ip-error-when-trying-to-update-dynamic-dn) explains a bit about what's going on. 93 | 94 | 95 | Possible Errors + Their Solutions 96 | ====== 97 | 98 | Can't locate Data/Validate/IP.pm in @INC (you may need to install the Data::Validate::IP module) 99 | ------ 100 | ```bash 101 | apt-get install libdata-validate-ip-perl 102 | ``` 103 | 104 | FATAL: Error loading the Perl module JSON::Any needed for Cloudflare update. 105 | ------ 106 | ```bash 107 | apt-get install libjson-any-perl 108 | ``` 109 | 110 | Can't exec "sendmail": No such file or directory at /usr/sbin/ddclient line 1584. 111 | ------ 112 | ```bash 113 | apt-get install sendmail 114 | ``` 115 | 116 | WARNING: local host name (server) is not qualified; 117 | ------ 118 | This is an error that sendmail may give you on install. If you want, you can change your hostname to be something like server.domain.com, which would be qualified. This is not necessary, though. 119 | 120 | Error loading the Perl module IO::Socket::SSL needed for SSL connect. 121 | ------ 122 | ```bash 123 | apt-get install libio-socket-ssl-perl 124 | ``` 125 | 126 | Final Thoughts 127 | ====== 128 | That's it! Your setup should be complete. Please let me know if you encounter any errors that aren't listed below and submit a pull request if you have any corrections, additions or improvements. 129 | 130 | Matt 131 | --------------------------------------------------------------------------------