Manipulate DNS records on various DNS providers in a standardized/agnostic way
Project description
lexicon
Manipulate DNS records on various DNS providers in a standardized/agnostic way.
Introduction
Lexicon provides a way to manipulate DNS records on multiple DNS providers in a standardized way. Lexicon has a CLI but it can also be used as a python library.
Lexicon was designed to be used in automation, specifically letsencrypt.
Providers
Only DNS providers who have an API can be supported by lexicon
.
The current supported providers are:
- Aliyun.com (docs)
- AuroraDNS (docs)
- AWS Route53 (docs)
- Azure DNS (docs)
- Cloudflare (docs)
- ClouDNS (docs)
- CloudXNS (docs)
- ConoHa (docs)
- Constellix (docs)
- DigitalOcean (docs)
- Dinahosting (docs)
- DirectAdmin (docs)
- DNSimple (docs: v1, v2)
- DnsMadeEasy (docs)
- DNSPark (docs)
- DNSPod (docs)
- Dreamhost (docs)
- EasyDNS (docs)
- Easyname (docs)
- EUserv (docs)
- ExoScale (docs)
- Gandi (docs: RPC (old) / LiveAPI)
- Gehirn (docs)
- Glesys (docs)
- GoDaddy (docs)
- Google Cloud DNS (docs)
- Gransy (sites subreg.cz, regtons.com and regnames.eu, docs)
- Hover (docs)
- Hurricane Electric DNS (docs)
- Hetzner (docs)
- Infoblox (docs)
- Internet.bs (docs)
- INWX (docs)
- Linode (docs)
- Linode v4 (docs)
- LuaDNS (docs)
- Memset (docs)
- Namecheap (docs)
- Namesilo (docs)
- Netcup (docs)
- NFSN (NearlyFreeSpeech)
- NS1 (docs)
- OnApp (docs)
- Online
- OVH (docs)
- Plesk (docs)
- PointHQ (docs)
- PowerDNS (docs)
- Rackspace (docs)
- Rage4 (docs)
- RcodeZero (docs)
- Sakura Cloud by SAKURA Internet Inc. (docs)
- SafeDNS by UKFast (docs)
- SoftLayer (docs)
- Subreg (deprecated, use Gransy)
- Transip (docs)
- UltraDNS (docs)
- Vultr (docs)
- Yandex (docs)
- Zeit (docs)
- Zilore (docs)
- Zonomi (docs)
Potential providers are as follows. If you would like to contribute one, follow the CONTRIBUTING.md and then open a pull request.
- AHNames (docs)
DurableDNS (docs)Can't set TXT records- cyon.ch
- Dyn (docs) :dollar: requires paid account
- Dynu
- EntryDNS (docs) :dollar: requires paid account
- FreeDNS (docs)
- Host Virtual DNS (docs) :dollar: requires paid account
- HostEurope
- Infoblox NIOS
- ironDNS (docs) :dollar: requires paid account
- ISPConfig
- InternetX autoDNS (docs)
- Knot DNS
- KingHost
- Liquidweb (docs) :dollar: requires paid account
- Loopia (docs) :dollar: requires paid account
- Mythic Beasts(docs)
- NFSN (NearlyFreeSpeech) (docs) :dollar: requires paid account
- RFC2136 (docs)
- Servercow (docs)
- selectel.com
- TELE3 (docs)
- UltraDNS (docs) :dollar: requires paid account
- UnoEuro API
- VSCALE
- WorldWideDns (docs) :dollar: requires paid account
- Zerigo (docs) :dollar: requires paid account
- Zoneedit (docs)
- Any others I missed
Setup
Warning: it is strongly advised with pip to install Lexicon in a Python virtual environment, in order to avoid interference between Python modules preinstalled on your system as OS packages and modules installed by pip (see https://docs.python-guide.org/dev/virtualenvs/).
To use lexicon as a CLI application, do the following:
pip install dns-lexicon
Some providers (like Route53 and TransIP) require additional dependencies. You can install provider specific dependencies separately:
pip install dns-lexicon[route53]
To install lexicon with the additional dependencies of every provider, do the following:
pip install dns-lexicon[full]
You can also install the latest version from the repository directly.
pip install git+https://github.com/AnalogJ/lexicon.git
and with Route 53 provider dependencies:
pip install git+https://github.com/AnalogJ/lexicon.git#egg=dns-lexicon[route53]
As an alternative you can also install Lexicon using the OS packages available for major Linux distributions (see lexicon
or dns-lexicon
package in https://pkgs.org/download/lexicon).
Usage
$ lexicon -h
usage: lexicon [-h] [--version] [--delegated DELEGATED]
{cloudflare,cloudxns,digitalocean,dnsimple,dnsmadeeasy,dnspark,dnspod,easydns,luadns,namesilo,nsone,pointhq,rage4,route53,vultr,yandex,zonomi}
...
Create, Update, Delete, List DNS entries
positional arguments:
{cloudflare,cloudxns,digitalocean,dnsimple,dnsmadeeasy,dnspark,dnspod,easydns,luadns,namesilo,nsone,pointhq,rage4,route53,vultr,yandex,zonomi}
specify the DNS provider to use
cloudflare cloudflare provider
cloudxns cloudxns provider
digitalocean digitalocean provider
...
rage4 rage4 provider
route53 route53 provider
vultr vultr provider
yandex yandex provider
zonomi zonomi provider
optional arguments:
-h, --help show this help message and exit
--version show the current version of lexicon
--delegated DELEGATED
specify the delegated domain
$ lexicon cloudflare -h
usage: lexicon cloudflare [-h] [--name NAME] [--content CONTENT] [--ttl TTL]
[--priority PRIORITY] [--identifier IDENTIFIER]
[--auth-username AUTH_USERNAME]
[--auth-token AUTH_TOKEN]
{create,list,update,delete} domain
{A,AAAA,CNAME,MX,NS,SPF,SOA,TXT,SRV,LOC}
positional arguments:
{create,list,update,delete}
specify the action to take
domain specify the domain, supports subdomains as well
{A,AAAA,CNAME,MX,NS,SPF,SOA,TXT,SRV,LOC}
specify the entry type
optional arguments:
-h, --help show this help message and exit
--name NAME specify the record name
--content CONTENT specify the record content
--ttl TTL specify the record time-to-live
--priority PRIORITY specify the record priority
--identifier IDENTIFIER
specify the record for update or delete actions
--auth-username AUTH_USERNAME
specify email address used to authenticate
--auth-token AUTH_TOKEN
specify token used authenticate
Using the lexicon CLI is pretty simple:
# setup provider environmental variables:
export LEXICON_CLOUDFLARE_USERNAME="myusername@example.com"
export LEXICON_CLOUDFLARE_TOKEN="cloudflare-api-token"
# list all TXT records on cloudflare
lexicon cloudflare list example.com TXT
# create a new TXT record on cloudflare
lexicon cloudflare create www.example.com TXT --name="_acme-challenge.www.example.com." --content="challenge token"
# delete a TXT record on cloudflare
lexicon cloudflare delete www.example.com TXT --name="_acme-challenge.www.example.com." --content="challenge token"
lexicon cloudflare delete www.example.com TXT --identifier="cloudflare record id"
Authentication
Most supported DNS services provide an API token, however each service implements authentication differently. Lexicon attempts to standardize authentication around the following CLI flags:
--auth-username
- For DNS services that require it, this is usually the account id or email address--auth-password
- For DNS services that do not provide an API token, this is usually the account password--auth-token
- This is the most common auth method, the API token provided by the DNS service
You can see all the --auth-*
flags for a specific service by reading the DNS service specific help: lexicon cloudflare -h
Environmental Variables
Authentication
Instead of providing Authentication information via the CLI, you can also specify them via Environmental Variables.
Every DNS service and auth flag maps to an Environmental Variable as follows: LEXICON_{DNS Provider Name}_{Auth Type}
So instead of specifying --auth-username
and --auth-token
flags when calling lexicon cloudflare ...
,
you could instead set the LEXICON_CLOUDFLARE_USERNAME
and LEXICON_CLOUDFLARE_TOKEN
environmental variables.
If you've got a subdomain delegation configured and need records configured within that (eg, you're trying to set test.foo.example.com
where foo.example.com
is configured as a separate zone), set LEXICON_DELEGATED
to the delegated domain.
LEXICON_DELEGATED=foo.example.com
TLD Cache
The tldextract library is used by Lexicon to find the actual domain name
from the provided FQDN (eg. domain.net
is the actual domain in www.domain.net
). Lexicon stores tldextract
cache
by default in ~/.lexicon_tld_set
where ~
is the current user's home directory. You can change this path using
the LEXICON_TLDEXTRACT_CACHE
environment variable.
For instance, to store tldextract
cache in /my/path/to/tld_cache
, you can invoke Lexicon like this from a Linux shell:
LEXICON_TLDEXTRACT_CACHE=/my/path/to/tld_cache lexicon myprovider create www.example.net TXT ...
Letsencrypt Instructions
Lexicon has an example dehydrated hook file that you can use for any supported provider. All you need to do is set the PROVIDER env variable.
PROVIDER=cloudflare dehydrated --cron --hook dehydrated.default.sh --challenge dns-01
Lexicon can also be used with Certbot and the included Certbot hook file (requires configuration).
TroubleShooting & Useful Tools
There is an included example Dockerfile that can be used to automatically generate certificates for your website.
ToDo list
- Create and Register a lexicon pip package.
- Write documentation on supported environmental variables.
- Wire up automated release packaging on PRs.
- Check for additional dns hosts with apis (from fog, dnsperf, libcloud)
- Get a list of Letsencrypt clients, and create hook files for them (letsencrypt clients)
Contributing Changes.
If the DNS provider you use is not already available, please consider contributing by opening a pull request and following the CONTRIBUTING.md
License
References
tox
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file dns-lexicon-3.3.26.tar.gz
.
File metadata
- Download URL: dns-lexicon-3.3.26.tar.gz
- Upload date:
- Size: 147.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.39.0 CPython/3.8.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ebc5e37034f86789bb89ad8a0f0b2e15a8fc14f84b94bdbc1fb3438b411cec6 |
|
MD5 | 0c122cb181b68801fb0c5e54cb478513 |
|
BLAKE2b-256 | df00a75fd9bda1e89f6028658be7836ed291025c3163647907151f852db26541 |