準備環(huán)境;
安裝bind包文件,關(guān)閉防火墻苞慢,更改Selinux配置文件;
centos7為主DNS, centos6為從和子dns;
#yum install bind
#systemctl disable firewalld
#systemctl stop firewalld
#getenforce
#vim /etc/selinux/config
permissive
#setenforce 0
#systemctl start named
dns安裝英妓;
1挽放、創(chuàng)建主dns;
2、創(chuàng)建從dns;
3蔓纠、創(chuàng)建子dns;
4辑畦、安裝bind-chroot;
1、主dns;
1腿倚、更改配置文件/etc/named.conf;
options {
// listen-on port 53 { localhost; }; --------可以注釋掉纯出,注釋掉后允許所有或localhost代表本地ip,主dns的ip
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
// allow-query { localhost;any;172.16.253.67; }; --------本地訪問的ip地址,所有,指定的ip;注釋掉后允許所有ip訪問敷燎;
allow-transfer { 192.168.226.134; }; ---------指定從服務(wù)器的ip,放置數(shù)據(jù)傳輸流失暂筝,防止除從機以外抓取數(shù)據(jù);
/*
*/
recursion yes; ---------------------允許遞歸查詢硬贯;
allow-update { any; }; -----------允許遠程更新數(shù)據(jù)庫焕襟;
dnssec-enable no; ---------創(chuàng)建子域時需要關(guān)閉;
dnssec-validation no; ----------創(chuàng)建子域時需要關(guān)閉饭豹;
2鸵赖、編輯數(shù)據(jù)庫文件路徑;
1墨状、可以再/etc/named.conf配置文件里進行編輯修改卫漫;
2、可以在/etc/named.rfc1912.zones配置文件里進行修改肾砂,一般在此修改文件列赎;
/etc/named.rfc1912.zones;參照格式,進行添加;
zone "localhost.localdomain" IN {
type master;
file "named.localhost";
allow-update { none; };
};
# zone "magedu.com" IN {
type master;
file "magedu.com.zone";
};
指明數(shù)據(jù)庫包吝,域與數(shù)據(jù)庫文件對應(yīng)關(guān)系饼煞;
3、創(chuàng)建數(shù)據(jù)庫文件诗越,拷貝/var/named/目錄下的文件砖瞧,進行修改;
#cp -p /var/named/named.localhost /var/named/magedu.com.zone
#vim /var/named/magedu.com.zone
$TTL 1D
@ IN SOA dns1.magedu.com. dnsadmin.magedu.com. (
202 ; serial
10M ; refresh
3M ; retry
1D ; expire
3D ) ; minimum
NS dns1
NS dns2
shanghai NS dns3
dns1 A 192.168.226.133
dns2 A 192.168.226.134 ---------指定從DNS的ip地址嚷狞;
dns3 A 192.168.226.134 ---------指定子域的ip地址块促;
websrv A 1.1.1.1
websrv A 3.3.3.3
ftpsrv A 2.2.2.2
www CNAME websrv -------別名
@ MX 10 mailsrv
@ MX 20 mailsrv
mailsrv1 A 6.6.6.6
mailsrv2 A 7.7.7.7
4、重新加載 或 重新啟動服務(wù)床未;
#rndc reload
#systemctl restart named
2竭翠、從dns;
1、編輯/etc/named.conf文件薇搁;
options {
// listen-on port 53 { 127.0.0.1; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
// allow-query { localhost; };
allow-transfer { none; }; --------防止傳輸數(shù)據(jù)斋扰;
2、編輯啃洋、/etc/named.rfc1912.zones文件传货;
編輯添加;
zone "magedu.com" IN {
type slave;
masters { 192.168.226.133; };
file "slaves/magedu.slave";
};
3宏娄、自動生成數(shù)據(jù)庫文件问裕,在/var/named/slaves目錄下;
[root@centos6 ~]# cd /var/named/slaves
[root@centos6 slaves]# ls
magedu.slave
[root@centos6 slaves]#
4绝编、重新加載 或 重新啟動服務(wù)僻澎;
#rndc reload
#service named restart
3、子dns;
1十饥、編輯窟勃、/etc/named.conf文件;
options {
// listen-on port 53 { 127.0.0.1; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
// allow-query { localhost; };
2逗堵、編輯秉氧、/etc/named.rfc1912.zones文件;
/etc/named.rfc1912.zones;參照格式蜒秤,進行添加汁咏;
zone "localhost.localdomain" IN {
type master;
file "named.localhost";
allow-update { none; };
};
# zone "shanghai.magedu.com" IN {
type master;
file "shanghai.magedu.com.zone";
};
3、創(chuàng)建數(shù)據(jù)庫文件作媚,拷貝/var/named/目錄下的文件攘滩,進行修改;
#cp -p /var/named/named.localhost /var/named/shanghai.magedu.com.zone
#vim /var/named/shanghai.magedu.com.zone
$TTL 86400 ; 1 day
@ IN SOA dns1 dnsadmin (
202 ; serial
600 ; refresh (10 minutes)
180 ; retry (3 minutes)
86400 ; expire (1 day)
259200 ; minimum (3 days)
)
NS dns1
dns1 A 192.168.226.134
websrv A 1.1.1.1
www CNAME websrv
4纸泡、安裝bind-chroot包漂问,文件路徑加深;
# systemctl start named-chroot;
[root@centos7 named]# pwd
/var/named/chroot/var/named
[root@centos7 named]# ls
chroot data dynamic magedu.com.zone named.ca named.empty named.localhost named.loopback shanghai.magedu.com.zone slaves
[root@centos7 named]#
相關(guān)命令蚤假;
Iptables -A INPUT -p tcp --dport 53 -j REJECT ------53端口栏饮; 禁用tcp
#rpm -q --scripts bind-chroot------查看腳本;生成服務(wù)的腳本磷仰;
Recursion yes; 遞歸查詢
Rndc flush----清除DNS緩存
查詢配置文件語法袍嬉;
#named-checkconf
#named-checkzone shanghai.magedu.com #/var/named/shanghai.magedu.com.zone
#nsupdate ------遠程更新數(shù)據(jù)庫;