Automatic deployment of CentOS Bind DNS

Source: Internet
Author: User
Tags nameserver egrep

I have recently studied the DNS Master/Slave service and have also made reference to many articles. Here I will record it to make it easier for you to avoid detours. The DNS service can be a more difficult part of the Linux service, especially the configuration file writing, an error may occur if one character is missing.

What is DNS? Simply put, it completes the domain name-to-IP resolution process. Simple domain names make it easier for people to remember, and do not need to remember a long IP address to access a website.

What is the DNS resolution process?

Step 1: When the client accesses a website and requests domain name resolution, it first looks for the local HOST file. If there is a corresponding domain name or IP address record, it will directly return it to the client. If not, send the request to the Local Domain Name Server:

Step 2: The local DNS server can resolve the request sent from the client, and the server directly returns the answer to the client.

Step 3: The local DNS server cannot parse requests sent from the client. There are two Resolution Methods:

1. Recursive resolution: the local DNS server sends a request to the root domain name server. The root domain name server resolves the request to the Local Domain Name Service and obtains the record to the local DNS server, the local DNS Server caches the records and returns the records to the client.

2. Iterative resolution: the local DNS server sends a request to the root domain name server. The Root Domain Name Server Returns the address of the next level domain name server that can resolve the request to the Local Domain Name Server, the local domain name server sends a request to the IP address returned by the root to obtain the domain name resolution record.

The above is just a brief introduction to DNS-related knowledge. The following describes how to use the script to automatically install and add domain name resolution. The script can be modified as needed: the script applies to CentOS x86_64 5.8 Series)

#! /Bin/sh # auto install config bind server # wugk 2013-08-28 # define the variable BND_ETC =/var/named/chroot/etcBND_VAR =/var/named/chroot/var/namedBAK_DIR =/data /backup/dns _ 'date + % Y % m % d-% H % m' # Backup named serverif [! -D $ BAK_DIR]; then echo "Please waiting Backup Named Config ............ "mkdir-p $ BAK_DIR cp-a/var/named/chroot/{etc, var} $ BAK_DIR cp-a/etc/named. * $ BAK_DIRfi # Define Shell Install FunctionInstall () {if [! -E/etc/init. d/named]; then rpm-e -- nodeps bind-utils rpm-e -- nodeps bind-libs rpm-e -- nodeps bind rpm-e bind-chroot rpm-e caching-nameserver rpm-ivh -- nodeps bind-9.3.6-20.P1.el5_8.6.x86_64.rpm bind-chroot-9.3.6-20.P1.el5_8.6.x86_64.rpm bind-libs-9.3.6-20.P1.el5_8.6.x86_64.rpm bind-utils-9.3.6-20.P1.el5_8.6.x86_64.rpm caching-nameserver-9.3.6-20.P1.el5_8.6.x86_64.rpm else echo ------------- ---------------------------------- Echo "The Named Server is exists, Please exit ......... "sleep 1 fi }## Define Shell Init FunctionInit_Config () {cd $ BND_ETC; ls. /* cp-p named. caching-nameserver.conf named. conf sed-I-e's/localhost;/any;/G'-e '/port/s/127.0.0.1/any/G' named. conf echo ------------------------------------------------- sleep 2 echo "The named. conf config Init success! "}## Define Shell Add Name FunctionAdd_named () {## DNS name read-p" Please Insert Into Your Add Name, Example 51cto.com: "NAME echo $ NAME | grep-E" com | cn | net | org "while [" $? "-Ne 0] do read-p" Please reInsert Into Your Add Name, Example 51cto.com: "NAME echo $ NAME | grep-E" com | cn | net | org "done # IP address read-p" Please Insert Into Your Name Server IP ADDress: "IP echo $ IP | egrep-o" ([0-9] {1, 3 }\.) {3} [0-9] {1, 3} "while [" $? "-Ne" 0 "] do read-p" Please reInsert Into Your Name Server IP ADDress: "IP echo $ IP | egrep-o" ([0-9] {1, 3 }\.) {3} [0-9] {1, 3} "done ARPA_IP = 'echo $ IP | awk-F. '{print $3 ". "$2 ". "$1} ''arpa_ip1 = 'echo $ IP | awk-F. '{print $4}' 'CD $ BND_ETC grep "$ NAME" named. rfc1912.zones if [$? -Eq 0]; then echo "The $ name is exist named. rfc1912.zones conf, please exit... "exitelse read-p" Please Insert Into SLAVE Name Server IP ADDress: "SLAVE echo $ SLAVE | egrep-o" ([0-9] {1, 3 }\.) {3} [0-9] {1, 3} "while [" $? "-Ne" 0 "] do read-p" Please Insert Into SLAVE Name Server IP ADDress: "SLAVE echo $ SLAVE | egrep-o" ([0-9] {1, 3 }\.) {3} [0-9] {1, 3} "done grep" rev "named. rfc1912.zones if [$? -Ne 0]; then cat> named. rfc1912.zones <EOF # 'date + % Y-% m-% d' Add $ NAME CONFIGzone "$ NAME" IN {type master; file "$ NAME. zone "; allow-transfer {$ SLAVE;}; also-policy {$ SLAVE ;}; allow-update {none ;};}; zone "$ ARPA_IP.in-addr.arpa" IN {type master; file "$ ARPA_IP.rev"; allow-transfer {$ SLAVE ;}; also-policy {$ SLAVE ;}; allow-update {none ;};}; EOF else cat >>> named. rfc1912.zones <EOF # 'date + % Y-% m-% d' Add $ NAME CONFIGzone "$ NAME" IN {type master; file "$ NAME. zone "; allow-transfer {$ SLAVE ;}; also-policy {$ SLAVE ;}; allow-update {none ;}; EOF fifi [$? -Eq 0] & echo "The $ NAME config name. rfc1912.zones success! "Sleep 3; echo" Please waiting config $ NAME zone File ............. "cd $ BND_VAR read-p" Please insert Name dns a host, EXample www or mail: "HOST read-p" Please insert Name dns a ns ip addr, EXample 192.168.111.130: "IP_HOST echo $ IP_HOST | egrep-o" ([0-9] {1, 3 }\.) {3} [0-9] {1, 3} "ARPA_IP2 = 'echo $ IP_HOST | awk-F. '{print $3 ". "$2 ". "$1} ''arpa_ip3 = 'echo $ IP_HOST | awk-F. '{print $4}' while ["$? "-Ne" 0 "] do read-p" Please Reinsert Name dns a ipaddress, EXample 192.168.111.130: "IP_HOST echo $ IP_HOST | egrep-o" ([0-9] {1, 3 }\.) {3} [0-9] {1, 3} "done cat> $ NAME. zone <EOF \ $ TTL 86400 @ in soa localhost. root. localhost. (43; serial (d. adams) 1 H; refresh 15 M; retry 1 W; expiry 1D); minimum in ns $ NAME. eof rev = 'ls *. rev 'ls *. rev>/dev/null if [$? -Ne 0]; then cat >>$ ARPA_IP.rev <EOF \ $ TTL 86400 @ in soa localhost. root. localhost. (1997022703; Serial 28800; Refresh 14400; Retry 3600000; Expire 86400); Minimum in ns $ NAME. EOF echo "$ host in a $ IP_HOST"> $ NAME. zone echo "$ ARPA_IP3 in ptr $ HOST. $ NAME. ">>$ ARPA_IP.rev [$? -Eq 0] & echo-e "The $ NAME config success: \ n $ host in a $ IP_HOST \ n $ ARPA_IP3 in ptr $ HOST. $ NAME. "else sed-I" 9a IN NS $ NAME. "$ REV echo" $ host in a $ IP_HOST "> $ NAME. zone echo "$ ARPA_IP3 in ptr $ HOST. $ NAME. ">>$ REV [$? -Eq 0] & echo-e "The $ NAME config success1: \ n $ host in a $ IP_HOST \ n $ ARPA_IP3 in ptr $ HOST. $ NAME. "fi }## Define Shell List A FunctionAdd_A_List () {if cd $ BND_VAR REV = 'ls *. rev 'read-p "Please Insert Into Your Add Name, Example 51cto.com:" NAME [! -E "$ NAME. zone "]; then echo" The $ NAME. zone File is not exist, Please ADD $ NAME. zone File: "Add_named; else read-p" Please Enter List Name a ns File, Example/tmp/name_list.txt: "FILE if [-e $ FILE]; then for I in 'cat $ FILE | awk '{print $2}' | sed "s/$ NAME // g" | sed's /\. $ // g'' # for I in 'cat $ FILE | awk '{print $1}' | sed "s/$ NAME // g" | sed's /\. $ // g'' do j = 'awk-v I = "$ I. $ NAME "'{if (I ==$ 2) print $1}' $ FIL E 'echo ------------------------------------------------------------- echo "The $ NAME. zone File is exist, Please Enter insert name host .... "sleep 1 ARPA_IP = 'echo $ j | awk-F. '{print $3 ". "$2 ". "$1} ''arpa_ip2 = 'echo $ j | awk-F. '{print $4}' 'echo "$ I IN A $ j"> $ NAME. zone echo "$ ARPA_IP2 in ptr $ I. $ NAME. ">>$ REV [$? -Eq 0] & echo-e "The $ NAME config success: \ n $ I in a $ j \ n $ ARPA_IP2 in ptr $ I. $ NAME. "done else echo" The $ FILE List File IS Not Exist ......., please exit... "fifi }## Define Shell Select Menu PS3 =" Please select Menu Name Config: "select I in" Automatic Installation of Bind Service "" automatic initialization of Bind configuration "" Add resolution domain name "" batch Add A record "docase $ I in" Automatic Installation of Bind Service ") install; "automatically initialize Bind configuration") Init_Config; "Add resolution domain name") Add_named; "add A record in batches") Add_A_List ;;*) echo merge sleep 1 echo "Please exec: sh $0 {Install (1) or Init_Config (2) or Add_named (3) or Add_config_A (4)}"; esacdone

Thank you very much for your reference in this article!

Http://blog.csdn.net/crazw/article/details/8986504

Http://www.xiaoxiaozi.com/2013/04/23/2409/

Http://1567045.blog.51cto.com/1557045/724332

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.