近来我被分配至DNS小组,来管理公司的DNS server。今天有点小任务就是将BIND8下面的配置迁移到BIND9
原始BIND8配置文件为
jupiter 600 CNAME newsnj chinanet-jiangsu 原始
转换成BIND9为
group group-cname4-jupiter.china.com {
#关键字 组名称即原始的2级域名
enabled yes; #是否启用
ttl 60; #ttl
cname newsnj.china.com; #cname到的地址
};
最后简单的考虑了下还是通过awk脚本来实现
1.原始DNS文本格式处理
cat 原始DNS内容 |sort -k 3 -k 5 -k 4|sed -e 's#\(cernet\)-[a-z]\{2,\}#\1#g'|uniq > DNS_final
2.转换格式为new dns conf内容
awk -f awk.script DNS_final
其中 awk.script 为 :
#!/usr/bin/awk -f
NR==1 {
LAST=$1;
#print "LAST="LAST;
printf "vserver "$1".sina.com.cn {\n";
printf "\tenabled yes;\n";
printf "\tttl 60;\n";
system("rm -f ./awk.final ./awk.tmp");
}
{
if($1==LAST)
{
if($3=="CNAME") #CNAME
{
if($5~/[[:alpha:]]/) #have a region
{
printf ("\t};\n\n");
printf ("\tgroup group-cname"NR"-"$1".sina.com.cn {");
printf("\n\t\tenabled yes;\n\t\tttl 60;\n\t\tcname "$4 ".sina.com.cn;\n\n");
STRING[NR-1]="group-cname"NR"-"$1".sina.com.cn view-"$5" 800;\n";
good=1;
#print "########test###########"STRING[NR-1];
}
else if($5~/^$/) #default
{
printf ("\t};\n\n");
printf ("\tgroup group-default-"$1".sina.com.cn {");
printf ("\n\t\tdefault yes;");
printf("\n\t\tenabled yes;\n\t\tttl 60;\n\t\tcname "$4 ".sina.com.cn;\n\n");
good=0;
}
}
if($3=="A") #A address
{
if($5~/[[:alpha:]]/) #have a region
{
if($5!=REGION)
{
REGION=$5;
printf ("\t};\n\n")
printf ("\tgroup group-"$5"-"$1".sina.com.cn {");
printf("\n\t\tenabled yes;\n\t\tttl 60;\n\t\taddress "$4 ";\n");
STRING[NR-1]="group-"$5"-"$1".sina.com.cn view-"$5" 800;\n";
good=1;
}
else if($5==REGION)
{
printf("\t\taddress "$4 ";\n");
STRING[NR-1]="group-"$5"-"$1".sina.com.cn view-"$5" 800;\n";
good=0;
}
}
if($5~/^$/) #default
{
if($5~NHK)
{
NHK=2;
printf ("\t};\n\n");
printf ("\tgroup group-default-"$1".sina.com.cn {");
printf ("\n\t\tdefault yes;");
printf("\n\t\tenabled yes;\n\t\tttl 60;\n\t\taddress "$4 ";\n");
good=0;
}
else
{
#if($4!=IPADDRESS)
printf("\t\taddress "$4 ";\n");
good=0;
}
}
}
}
else if ($1!=LAST&&good==1)
{
LAST=$1;
printf "\t};\n\trules { ";
for (a in STRING)
{
print STRING[a] >> "./awk.tmp"
}
system("sort ./awk.tmp|uniq > ./awk.final")
while( getline var <"./awk.final" )
{printf "\t\t"var"\n";}
printf ("\t};\n");
printf "vserver "$1".sina.com.cn {\n";
printf "\tenabled yes;\n";
printf "\tttl 60;\n";
for(a in STRING) {delete STRING[a]}
system("rm -f ./awk.final ./awk.tmp")
}
else
{
LAST=$1;
printf "\t};";
}
}
END {
if (good==1)
{ printf "\t};\n\trules { ";
for (a in STRING)
{
print STRING[a] >> "./awk.tmp"
}
system("sort ./awk.tmp|uniq > ./awk.final")
while( getline var <"./awk.final" )
{
printf "\t\t"var"\n";
}
printf "\t};\n};\n";}
else if (good==0)
{ printf "\t};\n};\n";
}
}
上述就是程序最终的精华算法部分了,还没有详细的描述功能。改天继续
To Be Continue…………………………
PS: 很菜的东西 请SPIDER不要盗了,免得被高手耻笑
BY IORI
CREATETIME 15TH DEC 2008
IN SINA
LASTMODIFY 14:00 18TH DEC 2008
阅读(779) | 评论(0) | 转发(0) |