Automatic DNS shell deployment

Source: Internet
Author: User
Tags domain name server
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, first find the local HOST file, as shown in figure

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 automatically install and add domain name resolution using a script. 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]; thenecho "Please waiting Backup Named Config ............ "mkdir-p $ BAK_DIRcp-a/var/named/chroot/{etc, var} $ BAK_DIRcp-a/etc/named. * $ BAK_DIRfi # Define Shell Install FunctionInstall () {if [! -E/etc/init. d/named]; thenrpm-e -- nodeps bind-utilsrpm-e -- nodeps bind-libsrpm-e -- nodeps bindrpm-e bind-chrootrpm-e caching-nameserverrpm-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 --------------------- ---------------------------- Echo "The Named Server is exists, Please exit ......... "sleep 1fi }## Define Shell Init FunctionInit_Config () {cd $ BND_ETC; ls. /* cp-p named. caching-nameserver.conf named. confsed-I-e's/localhost;/any;/G'-e '/port/s/127.0.0.1/any/G' named. confecho --------------------------------------------------- sleep 2 echo "The named. conf config Init success! "}## Define Shell Add Name FunctionAdd_named () {## DNS nameread-p" Please Insert Into Your Add Name, Example 51cto.com: "NAMEecho $ NAME | grep-E" com | cn | net | org "while [" $? "-Ne 0] doread-p" Please reInsert Into Your Add Name, Example 51cto.com: "NAMEecho $ NAME | grep-E" com | cn | net | org "done # IP addressread-p" Please Insert Into Your Name Server IP ADDress: "IPecho $ IP | egrep-o" ([0-9] {1, 3 }\.) {3} [0-9] {1, 3} "while [" $? "-Ne" 0 "] doread-p" Please reInsert Into Your Name Server IP ADDress: "IPecho $ IP | egrep-o" ([0-9] {1, 3 }\.) {3} [0-9] {1, 3} "doneARPA_IP = 'echo $ IP | awk-F. '{print $3 ". "$2 ". "$1} ''arpa _ IP1 = 'echo $ IP | awk-F. '{print $4}' 'CD $ BND_ETCgrep "$ NAME" named. rfc1912.zonesif [$? -Eq 0]; thenecho "The $ name is exist named. rfc1912.zones conf, please exit... "exitelseread-p" Please Insert Into SLAVE Name Server IP ADDress: "SLAVEecho $ SLAVE | egrep-o" ([0-9] {1, 3 }\.) {3} [0-9] {1, 3} "while [" $? "-Ne" 0 "] doread-p" Please Insert Into SLAVE Name Server IP ADDress: "SLAVEecho $ SLAVE | egrep-o" ([0-9] {1, 3 }\.) {3} [0-9] {1, 3} "donegrep" rev "named. rfc1912.zonesif [$? -Ne 0]; thencat> named. rfc1912.zones <
 
  
> Named. rfc1912.zones <
  
   
$ NAME. zone <
   
    
>/Dev/nullif [$? -Ne 0]; thencat >>$ ARPA_IP.rev <
    
     
> $ NAME. zoneecho "$ 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. "elsesed-I" 9a IN NS $ NAME. "$ REVecho" $ host in a $ IP_HOST "> $ NAME. zoneecho "$ 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 () {ifcd $ BND_VARREV = 'ls *. rev 'read-p "Please Insert Into Your Add Name, Example 51cto.com:" NAME [! -E "$ NAME. zone "]; thenecho" The $ NAME. zone File is not exist, Please ADD $ NAME. zone File: "Add_named; elseread-p" Please Enter List Name a ns File, Example/tmp/name_list.txt: "FILEif [-e $ FILE]; thenfori 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'' doj = 'awk-v I = "$ I. $ NAME "'{if (I ==$ 2) print $1}' $ file' echo -------- --------------------------------------------------- Echo "The $ NAME. zone File is exist, Please Enter insert name host .... "sleep 1ARPA_IP = 'echo $ j | awk-F. '{print $3 ". "$2 ". "$1} ''arpa _ IP2 = 'echo $ j | awk-F. '{print $4}' 'echo "$ I IN A $ j"> $ NAME. zoneecho "$ 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. "doneelseecho" The $ FILE List File IS Not Exist ......., please exit... "fifi }## Define Shell Select MenuPS3 =" 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
    
   
  
 


 


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.