Compendium of generic DNS utilities.


Some functions in the dnsutil execution module depend on dig.

salt.modules.dnsutil.A(host, nameserver=None)

Return the A record(s) for host.

Always returns a list.

CLI Example:

salt ns1 dnsutil.A
salt.modules.dnsutil.AAAA(host, nameserver=None)

Return the AAAA record(s) for host.

Always returns a list.

New in version 2014.7.5.

CLI Example:

salt ns1 dnsutil.AAAA
salt.modules.dnsutil.MX(domain, resolve=False, nameserver=None)

Return a list of lists for the MX of domain.

If the 'resolve' argument is True, resolve IPs for the servers.

It's limited to one IP, because although in practice it's very rarely a round robin, it is an acceptable configuration and pulling just one IP lets the data be similar to the non-resolved version. If you think an MX has multiple IPs, don't use the resolver here, resolve them in a separate step.

CLI Example:

salt ns1 dnsutil.MX
salt.modules.dnsutil.NS(domain, resolve=True, nameserver=None)

Return a list of IPs of the nameservers for domain

If 'resolve' is False, don't resolve names.

CLI Example:

salt ns1 dnsutil.NS
salt.modules.dnsutil.SPF(domain, record='SPF', nameserver=None)

Return the allowed IPv4 ranges in the SPF record for domain.

If record is SPF and the SPF record is empty, the TXT record will be searched automatically. If you know the domain uses TXT and not SPF, specifying that will save a lookup.

CLI Example:

salt ns1 dnsutil.SPF

Check that string ip_addr is a valid IP

CLI Example:

salt ns1 dnsutil.check_ip
salt.modules.dnsutil.hosts_append(hostsfile='/etc/hosts', ip_addr=None, entries=None)

Append a single line to the /etc/hosts file.

CLI Example:

salt '*' dnsutil.hosts_append /etc/hosts,
salt.modules.dnsutil.hosts_remove(hostsfile='/etc/hosts', entries=None)

Remove a host from the /etc/hosts file. If doing so will leave a line containing only an IP address, then the line will be deleted. This function will leave comments and blank lines intact.

CLI Examples:

salt '*' dnsutil.hosts_remove /etc/hosts
salt '*' dnsutil.hosts_remove /etc/hosts,
salt.modules.dnsutil.parse_hosts(hostsfile='/etc/hosts', hosts=None)

Parse /etc/hosts file.

CLI Example:

salt '*' dnsutil.parse_hosts
salt.modules.dnsutil.parse_zone(zonefile=None, zone=None)

Parses a zone file. Can be passed raw zone data on the API level.

CLI Example:

salt ns1 dnsutil.parse_zone /var/lib/named/
salt.modules.dnsutil.serial(zone='', update=False)

Return, store and update a dns serial for your zone files.

zone: a keyword for a specific zone

update: store an updated version of the serial in a grain

If update is False, the function will retrieve an existing serial or return the current date if no serial is stored. Nothing will be stored

If update is True, the function will set the serial to the current date if none exist or if the existing serial is for a previous date. If a serial for greater than the current date is already stored, the function will increment it.

This module stores the serial in a grain, you can explicitly set the stored value as a grain named dnsserial_<zone_name>.

CLI Example:

salt ns1 dnsutil.serial