标签:host name code 地址 str lag cas any group 目录
DNS系统的作用DNS系统在网络中的作用就是维护着一个地址数据库,其中记录了各种主机域名与IP地址的对应关系,以便为客户机提供正向或反向的地址查询服务。
BIND不是唯一能够提供域名服务的DNS程序,但它却是应用最为广泛的,BIND可以运行在大多数Linux主机中。
[root@localhost ~]# yum install bind -y //CentOS 7连接网络,可以直接使用yum安装
/usr/sbin/named
/etc/named.conf
/var/named/
options{
listen-on port 53 {本地IP地址} //监听地址和端口
directory ”/var/named“; //区域数据文件的默认存放位置
allow-query {192.168.1.0/24;173.16.16.0/24; //允许使用本DNS服务的网段
};
区域配置部分
设置本服务器提供域名解析的特定DNS区域
包括域名、服务器角色、数据文件名等
正向解析
zone "yun.com" IN { //正向“yun.com”区域
type master; //区域类型为主区域
file "yun.com.zone"; //区域数据文件为“yun.com.zone”
allow-transfer {173.16.16.2}; //允许下载的从服务器地址
};
反向解析
zone "16.16.173.in-addr.arpa" IN { //反向“173.16.16.0/24”区域
type master;
file "173.16.16.arpa"; //区域数据文件为"173.16.16.arpa"
allow-update { none; };
};
区域数据配置文件
全局TTL配置项及SOA记录 SOA:资源起始记录
$TTL 1D //有效解析记录的生存周期
@ IN SOA @ rname.invalid. ( //SOA标记、域名、管理邮箱
0 ; serial //更新序列号,可以是10位以内的整数
1D ; refresh //刷新时间,重新下载地址数据的间隔
1H ; retry //重试延时,下载失败后的重试间隔
1W ; expire //失效时间,超过该时间仍无法下载则放弃
3H ) ; minimum //无效解析记录的生存周期
? 域名解析记录
NS:域名服务器记录 (Name Service)
MX:邮件交换记录 (Mail Exchange)
A:地址记录,只用在正向解析区域中 (Address)
CNAME:别名记录(Canonical Name)
“*” IN IP:泛域名解析
PTR:指针记录,只用反向解析区域中
记录的第一列指定IP地址中的主机地址部分即可
/etc/named.conf
主要配置文件 控制系统全局 (include 包含)
/etc/named.rfc1912.zones
区域配置文件 控制具体单个区域
/var/named/named.localhost
区域数据配置文件 区域信息1、安装BIND软件
[root@localhost ~]# yum install bind -y
已加载插件:fastestmirror, langpacks
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/4): base/7/x86_64/group_gz | 166 kB 00:00:00
(2/4): extras/7/x86_64/primary_db | 215 kB 00:00:00
...//省略部分内容...
已安装:
bind.x86_64 32:9.9.4-74.el7_6.2
作为依赖被升级:
bind-libs.x86_64 32:9.9.4-74.el7_6.2 bind-libs-lite.x86_64 32:9.9.4-74.el7_6.2 bind-license.noarch 32:9.9.4-74.el7_6.2
bind-utils.x86_64 32:9.9.4-74.el7_6.2
完毕!
2、查看配置文件的存放位置,方便我们编辑配置文件
[root@localhost named]# rpm -qc bind
/etc/logrotate.d/named
/etc/named.conf //主配置文件位置
/etc/named.iscdlv.key
/etc/named.rfc1912.zones //区域配置文件位置
/etc/named.root.key
/etc/rndc.conf
/etc/rndc.key
/etc/sysconfig/named
/var/named/named.ca
/var/named/named.empty
/var/named/named.localhost //区域数据配置文件
/var/named/named.loopback
3、更改主配置文件(此处主要修改缉监听地址和权限开发两处)
[root@localhost named]# vim /etc/named.conf
...//省略部分内容...
// See the BIND Administrator‘s Reference Manual (ARM) for details about the
// configuration located in /usr/share/doc/bind-{version}/Bv9ARM.html
options {
listen-on port 53 { 192.168.144.133; }; //修改地址为监听自己的本地地址
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";
recursing-file "/var/named/data/named.recursing";
secroots-file "/var/named/data/named.secroots";
allow-query { any; }; //权限放开,允许任何的主机都可以使用DNS服务
/*
- If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
...//省略部分内容...
pid-file "/run/named/named.pid"; //进程文件的存放位置,不要改动
session-keyfile "/run/named/session.key";
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN { //根域服务器的解析,不要改动
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones"; //著配置文件包含的数据文件信息,不要更改
include "/etc/named.root.key";
4、修改主配置文件包含的区域配置文件信息
[root@localhost named]# vim /etc/named.rfc1912.zones
// named.rfc1912.zones:
//
// Provided by Red Hat caching-nameserver package
//
// ISC BIND named zone configuration for zones recommended by
// RFC 1912 section 4.1 : localhost TLDs and address zones
// and http://www.ietf.org/internet-drafts/draft-ietf-dnsop-default-local-zones-02.txt
// (c)2007 R W Franks
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
zone "localhost.localdomain" IN {
type master; //正向解析文件的配置模板
file "named.localhost";
allow-update { none; };
};
//正向解析区域配置文件位置
zone "localhost" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
type master; //ipv6解析文件的配置模板
file "named.loopback";
allow-update { none; };
};
//反向解析区域配置文件位置
zone "1.0.0.127.in-addr.arpa" IN {
type master;
file "named.loopback"; //反向解析文件的配置模板
allow-update { none; };
...//省略部分内容...
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
zone "localhost.localdomain" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "localhost" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "kgc.com" IN { //复制模板,更改区域名
type master;
file "kgc.com.zone"; //更改区域数据文件名
allow-update { none; };
};
zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};
zone "1.0.0.127.in-addr.arpa" IN {
type master;
...//省略部分内容...
5、创建区域数据文件,使区域文件可以读取数据文件
[root@localhost named]# cd /var/named/ //进入区域数据文件存放目录
[root@localhost named]# ls //查看目录信息
data dynamic named.ca named.empty named.localhost named.loopback slaves
[root@localhost named]# cp -p named.localhost kgc.com.zone //递归复制,创建kgc.com.zone文件
[root@localhost named]# ls //查看是否创建kgc.com.zone文件
data dynamic kgc.com.zone named.ca named.empty named.localhost named.loopback slaves
[root@localhost named]# vim kgc.com.zone //编辑区域数据文件
$TTL 1D
@ IN SOA kgc.com. admin.kgc.com. ( //更改域名、管理邮箱,主要后面的“.”不能少
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS kgc.com. //更改域名服务器记录地址
A 192.168.144.133 //更改正向解析条目地址
IN MX 10 mail.kgc.com. //添加邮件交换记录地址
www IN A 192.168.100.99 //添加www域名的解析地址
ftp IN A 192.168.100.88 //添加ftp域名解析地址
smtp IN CNAME www //添加别名解析记录
* IN A 8.8.8.8 //添加泛域名解析地址
~
~
:wq //保存退出
6、关闭防火墙与增强安全功能,方便客户端访问,然后启动DNS服务。
[root@localhost named]# systemctl stop firewalld.service //关闭防火墙
[root@localhost named]# setenforce 0 //关闭增强型安全更能
[root@localhost named]# systemctl start named //启动DNS服务
[root@localhost named]# systemctl status named //查看服务
● named.service - Berkeley Internet Name Domain (DNS) //DNS正常启动
Loaded: loaded (/usr/lib/systemd/system/named.service; disabled; vendor preset: disabled)
Active: active (running) since 四 2019-09-05 17:36:31 CST; 11s ago
Process: 7425 ExecStart=/usr/sbin/named -u named -c ${NAMEDCONF} $OPTIONS (code=exited, status=0/SUCCESS)
Process: 7422 ExecStartPre=/bin/bash -c if [ ! "$DISABLE_ZONE_CHECKING" == "yes" ]; then /usr/sbin/named-checkconf -z "$NAMEDCONF"; else echo "Checking of zone files is disabled"; fi (code=exited, status=0/SUCCESS)
Main PID: 7427 (named)
CGroup: /system.slice/named.service
└─7427 /usr/sbin/named -u named -c /etc/named.conf
9月 05 17:36:31 localhost.localdomain named[7427]: managed-keys-zone: loaded serial 0
9月 05 17:36:31 localhost.localdomain named[7427]: zone 0.in-addr.arpa/IN: loaded serial 0
9月 05 17:36:31 localhost.localdomain named[7427]: zone 1.0.0.127.in-addr.arpa/IN: loaded serial 0
9月 05 17:36:31 localhost.localdomain named[7427]: zone kgc.com/IN: loaded serial 0
9月 05 17:36:31 localhost.localdomain named[7427]: zone localhost.localdomain/IN: loaded serial 0
9月 05 17:36:31 localhost.localdomain named[7427]: zone 1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0...ial 0
9月 05 17:36:31 localhost.localdomain named[7427]: zone localhost/IN: loaded serial 0
9月 05 17:36:31 localhost.localdomain named[7427]: all zones loaded
9月 05 17:36:31 localhost.localdomain named[7427]: running
9月 05 17:36:31 localhost.localdomain systemd[1]: Started Berkeley Internet Name Domain (DNS).
Hint: Some lines were ellipsized, use -l to show in full.
[root@localhost named]# echo "nameserver 192.168.144.133" > /etc/resolv.conf
//覆盖域名解析地址文件信息,因为我们自己搭建的DNS服务器就要解析我们自己的地址,所以这边直接覆盖掉域名解析地址文件
[root@localhost named]# cat /etc/resolv.conf
nameserver 192.168.144.133 //以覆盖原信息
7、使用host命令常看DNS解析服务是否搭建成功
[root@localhost named]# host www.kgc.com //解析域名www.kgc.com
www.kgc.com has address 192.168.100.99 //成功解析IP地址
[root@localhost named]# host ftp.kgc.com //解析域名ftp.kgc.com
ftp.kgc.com has address 192.168.100.88 //成功解析IP地址
[root@localhost named]# host aaa.kgc.com //泛域名解析
aaa.kgc.com has address 8.8.8.8 //成功解析IP地址
[root@localhost named]# host smtp.kgc.com //别名解析
smtp.kgc.com is an alias for www.kgc.com.
www.kgc.com has address 192.168.100.99 //成功解析IP地址
1、继续上面的配置,进入区域配置文件中更改区域配置反向解析区域模板
[root@localhost named]# vim /etc/named.rfc1912.zones
...//省略部分内容...
zone "kgc.com" IN {
type master;
file "kgc.com.zone";
allow-update { none; };
};
zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};
zone "1.0.0.127.in-addr.arpa" IN {
type master;
file "named.loopback"; //复制此处模板
allow-update { none; };
};
zone "100.168.192.in-addr.arpa" IN { //更改区域地址,反向填写
type master;
file "yun.com.local"; //更改区域数据文件名
allow-update { none; };
};
zone "0.in-addr.arpa" IN {
type master;
file "named.empty";
...//省略部分内容...
2、进入区域数据文件存放目录建立区域数据文件,与区域文件中更给的区域数据文件名保持一致,并进入更改区域数据文件
[root@localhost named]# cd /var/named/ //进入目录
[root@localhost named]# ls //查看
data dynamic kgc.com.zone named.ca named.empty named.localhost named.loopback slaves
[root@localhost named]# cp -p kgc.com.zone yun.com.local //递归复制
[root@localhost named]# vim yun.com.local //进入编辑数据信息
$TTL 1D
@ IN SOA yun.com. admin.yun.com. ( //此处kgc改为yun
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS yun.com. //此处kgc改为yun
A 192.168.144.133
99 IN PTR www.yun.com. //更改为方向解析地址
88 IN PTR ftp.yun.com. //更改为方向解析地址
...//省略部分内容...
3、重启DNS服务,并检测反向解析是否创建成功
[root@localhost named]# systemctl restart named //重启服务
[root@localhost named]# host 192.168.100.99 //解析IP地址
99.100.168.192.in-addr.arpa domain name pointer www.yun.com. //成功解析出域名
[root@localhost named]# host 192.168.100.88 //解析IP地址
88.100.168.192.in-addr.arpa domain name pointer ftp.yun.com. //成功解析出域名
1、上面我们成功创建了主服务器,这个时候我们重新开启一台CentOS 7系统,作为DNS的从服务器,查看从服务器的IP地址,并关闭防火墙功能与增强性安全功能,使此服务器方便客户机与主服务器连接
[root@localhost ~]# ifconfig //查看网卡信息
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.144.135 netmask 255.255.255.0 broadcast 192.168.144.255
inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link>
inet6 fe80::ad78:663f:1f02:22e4 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:75:9f:c8 txqueuelen 1000 (Ethernet)
RX packets 1049 bytes 1282518 (1.2 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
...//省略部分内容...
[root@localhost ~]# systemctl stop firewalld.service //关闭防火墙
[root@localhost ~]# setenforce 0 //关闭增强性安全功能
2、在从服务器中安装BIND软件,并更改DNS配置文件信息
[root@localhost ~]# yum install bind -y //安装DNS服务软件BIND
已加载插件:fastestmirror, langpacks
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/4): base/7/x86_64/group_gz | 166 kB 00:00:00
(2/4): extras/7/x86_64/primary_db | 215 kB 00:00:00
...//省略部分内容...
[root@localhost ~]# vim /etc/named.conf //进入编辑主配置文件
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
// See the BIND Administrator‘s Reference Manual (ARM) for details about the
// configuration located in /usr/share/doc/bind-{version}/Bv9ARM.html
options {
listen-on port 53 { 192.168.144.135; }; //更改监听地址为本机地址
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";
recursing-file "/var/named/data/named.recursing";
secroots-file "/var/named/data/named.secroots";
allow-query { any; }; //权限放开,允许任何的主机都可以使用DNS服务
/*
- If you are building an AUTHORITATIVE DNS server, do NOT enable recursion.
- If you are building a RECURSIVE (caching) DNS server, you need to enable
recursion.
...//省略部分内容...
[root@localhost ~]# vim /etc/named.rfc1912.zones //修改区域配置文件
// RFC 1912 section 4.1 : localhost TLDs and address zones
// and http://www.ietf.org/internet-drafts/draft-ietf-dnsop-default-local-zones-02.txt
// (c)2007 R W Franks
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
zone "localhost.localdomain" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "localhost" IN {
type master;
file "named.localhost"; //复制此模板
allow-update { none; };
};
zone "kgc.com" IN { //粘贴并更新域名与主服务器相同
type slave; //设置类型为slave
file "slaves/kgc.com.zone"; //区域数据文件地址我们将从主服务器同步到slaves目录中
masters { 192.168.144.133; }; //删除原条目更改为指向主服务器的地址
};
zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};
...//省略部分内容...
[root@localhost ~]# cd /var/named //进入区域数据文件存放目录
[root@localhost named]# ls //查看确定目录内是否有slaves命令
data dynamic named.ca named.empty named.localhost named.loopback slaves
[root@localhost named]# ls slaves/ //进入目录,查看是否有内容
[root@localhost named]# //目前还没有内容
3、回到主服务器,更改配置文件,使主服务器与从服务器同步,完成后重启DNS服务
[root@localhost named]# vim /etc/named.rfc1912.zones //编辑主服务区域配置文件
//
zone "localhost.localdomain" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "localhost" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "kgc.com" IN {
type master;
file "kgc.com.zone";
allow-transfer { 192.168.144.135; }; //此处更改为指向从服务器的地址
};
zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};
zone "1.0.0.127.in-addr.arpa" IN {
type master;
...//省略部分内容...
[root@localhost named]# systemctl restart named //重启DNS服务
4、回到从服务器,启动DNS服务,查看slaves目录内是否有同步的区域数据文件,然后与主服务一样编辑内容覆盖域名解析地址文件信息。
[root@localhost named]# systemctl restart named //启动DNS服务
[root@localhost named]# ls slaves/
kgc.com.zone
[root@localhost named]# echo "nameserver 192.168.144.135" > /etc/resolv.conf
[root@localhost named]# cat /etc/resolv.conf
nameserver 192.168.144.135
5、使用从服务解析域名,看是否可以解析、解析结果是否相同,如果相同表示我们建立的主从服务器成功。
[root@localhost named]# host www.kgc.com //解析域名www.kgc.com
www.kgc.com has address 192.168.100.99 //解析地址与主服务器相同
[root@localhost named]# host ftp.kgc.com //解析域名ftp.kgc.com
ftp.kgc.com has address 192.168.100.88 //解析地址与主服务器相同
[root@localhost named]# host aaa.kgc.com //反域名解析
aaa.kgc.com has address 8.8.8.8 //解析地址与主服务器相同
[root@localhost named]# host smtp.kgc.com //别名解析
smtp.kgc.com is an alias for www.kgc.com.
www.kgc.com has address 192.168.100.99 //解析地址与主服务器相同
标签:host name code 地址 str lag cas any group 目录
原文地址:https://blog.51cto.com/14473285/2435947