Automating DNS operations using Infoblox and Python

Gopi Narayanaswamy
3 min readOct 24, 2020

--

What are DNS records?

Domain Name System (DNS) records are keeps the internet and intranet working as customer expects, the system basically points to IP address of domain name of the customer environment such as xyz.com. We need the DNS system and its records to keep the internet functioning and connected.

Before the DNS records, obtaining domain name and registration are important

Nameservers

A domain’s nameservers are playing vital role because they identify what set of servers any requests should reference in order to obtain a domain’s DNS records. Your domain should have it’s nameservers pointed to wherever you are intending to manage your site’s DNS records.

Nameserver is a server on the Internet specialized in handling queries regarding the location of the domain name’s various services. In easy words, name servers define your domain’s current DNS provider.

A DNS Record is a single flat entry that gives the instructions to particular zone on how to handle any given request based on type. There are many types of DNS Records, below are the few commonly used

· A Records

· CNAMES

· MX Records

· TXT Records

· PTR Records

· Alias Records

Each individual DNS record is assigned a type and information needed for that type of record.

A DNS Zone is like a container of all the DNS records for a specific domain and only that domain.

Please visit more details of DNS records https://ns1.com/resources/dns-records-explained

What is infoblox?

Infoblox is one of the Network management and automation tool used widely. Infoblox delivers essential technology to enable customers to manage, control and optimize DNS, DHCP, IPAM (DDI). Infoblox’s patented Grid™ technology helps businesses automate complex network control functions to reduce costs and increase security and uptime — building bulletproof, scalable and efficient networks.

Now, we see how to make DNS operations easy with Python and Infoblox

Python DNS resolver — The dig command

DNSpython is a module to handle all the dns records. It can be used for queries, zone transfers, and dynamic updates.

DNSpython has inbuilt class called resolver used for querying the records

Above is a simple program to query A, NS and Cname for Yahoo.com using external name server “8.8.8.8”

The name server can be changed to your internal server when you query your organizations internal records

Creating ‘A’ record in infoblox

from infoblox_client import connector

from infoblox_client import objects

Python infoblox client for doing infoblox operations or you can connect through requests module

Connect to the infoblox

from infoblox_client import connector

opts = {‘host’: ‘192.168.1.10’, ‘username’: ‘admin’, ‘password’: ‘admin’}

conn = connector.Connector(opts)

Connect using request method

import requests

from requests.auth import HTTPBasicAuth

requests.packages.urllib3.disable_warnings()

class Infoblox():

def __init__(self):

self.server = ‘infoblox.local’

self.wapiver = ‘/wapi/v1.7.3/’

self.user = ‘user’

self.password = ‘pass’

Create a network view, and network:

nview = objects.NetworkView.create(conn, name=’my_view’)

network = objects.Network.create(conn, network_view=’my_view’, cidr=’192.168.1.0/24')

Create a host record:

my_ip = objects.IP.create(ip=’192.168.1.25', mac=’aa:bb:cc:11:22:33')

hr = objects.HostRecord.create(conn, view=’my_dns_view’,

name=’my_host_record.my_zone.com’, ip=my_ip)

Please check my below program creates ‘A’ record for given domain name and IP

https://github.com/ngopi37/Infoblox_dns_records

Its validates IP address — If already there, validate ip address & etc

Its validates Domain name your entered using regex and do profanity check for bad words in domain

Its valid using python Dns resolver to check A record already there

Finally creates the A record

--

--

No responses yet