Skip to Content
Python for Unix and Linux System Administration
book

Python for Unix and Linux System Administration

by Noah Gift, Jeremy M. Jones
August 2008
Intermediate to advanced content levelIntermediate to advanced
458 pages
12h 47m
English
O'Reilly Media, Inc.
Content preview from Python for Unix and Linux System Administration

Chapter 14. Pragmatic Examples

Managing DNS with Python

Managing a DNS server is a fairly straightforward task compared to, say, an Apache configuration file. The real problem that afflicts data centers and web hosting providers, though, is performing programatic large-scale DNS changes. It turns out that Python does quite a good job in this regard with a module called dnspython. Note there is also also another DNS module named PyDNS, but we will be covering dnspython.

Make sure you refer to the official documentation: http://www.dnspython.org/. There is also a great article on using dnspython here: http://vallista.idyll.org/~grig/articles/.

To get started using dnspython, you will only need to do an easy_install as the package is listed in the Python Package Index.

 ngift@Macintosh-8][H:10048][J:0]# sudo easy_install dnspython
 Password:
 Searching for dnspython
 Reading http://pypi.python.org/simple/dnspython/
 [output supressed]

Next, we explore the module with IPython, like many other things in the book. In this example, we get the A and MX records for http://oreilly.com:

In [1]: import dns.resolver
In [2]: ip = dns.resolver.query("oreilly.com","A")
In [3]: mail = dns.resolver.query("oreilly.com","MX")
In [4]: for i,p in ip,mail:
....:     print i,p
....:     
....:     
208.201.239.37 208.201.239.36
20 smtp1.oreilly.com. 20 smtp2.oreilly.com.

In Example 14-1, we assign the “A” record results to ip and the “MX” records to mail. The “A” results are on top, and the “MX” records are on the bottom. Now ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Linux Fundamentals

Linux Fundamentals

Sander van Vugt
UNIX and Linux System Administration Handbook, 5th Edition

UNIX and Linux System Administration Handbook, 5th Edition

Trent R. Hein, Evi Nemeth, Garth Snyder, Ben Whaley, Dan Mackin

Publisher Resources

ISBN: 9780596515829Supplemental ContentErrata Page