AI智能
改变未来

每天一个shell脚本(13)脚本配置bind(DNS服务)

如有BUG请看客老爷指出即可,作者正在茁壮成长中!

#!/bin/bashname_rfc(){echo \'zone \"\'\"$URL\"\'\" IN {\'echo \"	type master;\"echo \'	file \"\'\"$zone\"\'\";\'echo \"	allow-update { none; };\"echo \"};\"}new_zone(){read -p \"请输入需要解析的IP--->\" IPaddrecho \"www   IN   A   $IPaddr\"}hint(){echo \"请输入要添加的域名,范例(jd.com)\"read -p \"-->\" URLzone=\"$URL\"\'.zone\'}if_fi(){while truedohintls /var/named/ | grep \"$URL\" &> /dev/nullif [ $? -eq 0 ]thenbreakelseecho \"域名不存在,请重新输入\"fidone}read -p \"是否为第一次配置named服务(Y/N)\" choicewhile truedocase $choice inY|y){yum -y install bind &> /dev/nullipadd=`ifconfig ens33 | grep \"inet \" | awk \'{print $2}\'`echo \"注意!本机IP为$ipadd\"echo \"请输入监听IP,格式范例(10.0.0.1;)\"read -p \"---->:\" IPdnsip=`cat /etc/named.conf | grep \"listen-on port 53\" | awk \'{print $5}\'`sed -i \"s/$dnsip/$IP/g\" /etc/named.confsed -i \"18s/localhost/any/g\" /etc/named.confbreak};;N|n){break};;*){echo \"请重新输入\"};;esacdoneunset choicewhile truedoecho \"1-->添加新的域名;\"echo \"2-->在现有域名添加主机名;\"echo \"3-->删除整个域名;\"echo \"4-->删除现有域名的主机名;\"echo \"5-->退出;\"read -p \"-->\" choicecase $choice in1){while truedohintls /var/named/ | grep \"$URL\" &> /dev/nullif [ $? -eq 1 ]thenbreakelseecho \"域名重复,请重新输入\"fidonename_rfc >> /etc/named.rfc1912.zonescp -p /var/named/named.localhost /var/named/$zoneecho \"请输入主机名,范例(www)\"read -p \"-->\" hostnamesed -i \"s/@/$hostname.$URL./2\" /var/named/$zonesed -i \"3,8s/@/$hostname.$URL./g\" /var/named/$zonesed -i \"9,+5d\" /var/named/$zonenew_zone >> /var/named/$zonesystemctl reload namedecho \"添加成功!\"};;2){if_finew_zone >> /var/named/$zonesystemctl reload namedecho \"添加成功!\"};;3){if_firm -rf /var/named/$zonesed -i \"/$URL/,+4d\" /etc/named.rfc1912.zonessystemctl reload namedecho \"删除成功!\"};;4){unset IPaddrif_firead -p \"请输入要删除解析的IP--->\" IPaddrsed -i \"/$IPaddr/d\" /var/named/$zoneecho \"删除成功!\"};;5){echo \"bye!bye!\"exit};;esacdone
赞(0) 打赏
未经允许不得转载:爱站程序员基地 » 每天一个shell脚本(13)脚本配置bind(DNS服务)