私有云搭建DNS服務(wù)器的方法
1. 服務(wù)器準(zhǔn)備
172.16.23.137 DNS服務(wù)器吼拥, 以下簡稱 server
172.16.23.139 客戶端測試服務(wù)器, 以下簡稱 client
2. 首關(guān)閉防火墻和selinux (兩個服務(wù)器都操作)
[root@localhost ~]# systemctl stop firewalld
[root@localhost ~]# systemctl disable firewalld
[root@localhost ~]# sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
[root@localhost ~]# setenforce 0
以下是server服務(wù)器的操作
1. 查看ip
[root@localhost ~]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.23.137 netmask 255.255.255.0 broadcast 172.16.23.255
inet6 fe80::2a6e:d4ff:fe88:c794 prefixlen 64 scopeid 0x20<link>
ether 28:6e:d4:88:c7:94 txqueuelen 1000 (Ethernet)
RX packets 7195317 bytes 2342937901 (2.1 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 199376 bytes 25216420 (24.0 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
2、DNS服務(wù)端安裝bind包聊浅,并設(shè)置開機自啟
[root@DNSserver ~]# yum install -y bind
[root@DNSserver ~]# systemctl start named
[root@DNSserver ~]# systemctl enable named
Created symlink /etc/systemd/system/multi-user.target.wants/named.service → /usr/lib/systemd/system/named.service.
[root@localhost ~]# systemctl status named
● named.service - Berkeley Internet Name Domain (DNS)
Loaded: loaded (/usr/lib/systemd/system/named.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2020-12-01 14:06:49 CST; 19h ago
Process: 233243 ExecStop=/bin/sh -c /usr/sbin/rndc stop > /dev/null 2>&1 || /bin/kill -TERM $MAINPID (code=exited, status=0/SUCCESS)
Process: 233260 ExecStart=/usr/sbin/named -u named -c ${NAMEDCONF} $OPTIONS (code=exited, status=0/SUCCESS)
Process: 233255 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: 233261 (named)
Tasks: 11
CGroup: /system.slice/named.service
└─233261 /usr/sbin/named -u named -c /etc/named.conf
Dec 02 09:09:59 localhost.localdomain named[233261]: network unreachable resolving './DNSKEY/IN': 2001:500...#53
Dec 02 09:09:59 localhost.localdomain named[233261]: network unreachable resolving './NS/IN': 2001:500:2d::d#53
Dec 02 09:09:59 localhost.localdomain named[233261]: network unreachable resolving './DNSKEY/IN': 2001:500...#53
Dec 02 09:09:59 localhost.localdomain named[233261]: network unreachable resolving './NS/IN': 2001:500:2::c#53
Dec 02 09:09:59 localhost.localdomain named[233261]: network unreachable resolving './DNSKEY/IN': 2001:500...#53
Dec 02 09:09:59 localhost.localdomain named[233261]: network unreachable resolving './NS/IN': 2001:500:9f::42#53
Dec 02 09:09:59 localhost.localdomain named[233261]: network unreachable resolving './DNSKEY/IN': 2001:dc3...#53
Dec 02 09:09:59 localhost.localdomain named[233261]: network unreachable resolving './NS/IN': 2001:dc3::35#53
Dec 02 09:10:09 localhost.localdomain named[233261]: resolver priming query complete
Dec 02 09:10:09 localhost.localdomain named[233261]: managed-keys-zone: Unable to fetch DNSKEY set '.': ti...out
3、在/etc/named.conf文件里面修改全局配置信息
[root@DNSserver ~]# vim /etc/named.conf
..........
options {
listen-on port 53 { any; }; //中括號里面講IP地址換成any
listen-on-v6 port 53 { any; }; //同上
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";
secroots-file "/var/named/data/named.secroots";
recursing-file "/var/named/data/named.recursing";
allow-query { any; }; //同上
..........
4蛋辈、在/etc/named.rfc1912.zones子配置文件里面添加正向和反向的解析區(qū)域
[root@localhost ~]# arpaname 172.16.23.137
137.23.16.172.IN-ADDR.ARPA
## 在文件的最后添加正向和反向的解析文件
[root@DNSserver ~]# vim /etc/named.rfc1912.zones
zone "moyu.com" IN {
type master;
file "moyu.zone";
};
zone "23.16.172.in-addr.arpa" IN {
type master;
file "172.16.23.arpa";
};
正向:
zone:代表一個區(qū)域
" " : 雙引號(英文)里面寫入的是自己域名
type master : master 代表是主域名服務(wù)器
file " ":雙引號里面寫文件與在 /var/named下創(chuàng)建的文件名相同
反向:
" ":雙引號里面寫入的是反ip瑟慈,例如:0.0.10.id-addr.arpa說明反向可以解析10.0.0.X網(wǎng)段的所有IP地址域名解析
可以使用:arpaname IP 查看自己的服務(wù)器IP的反IP
注釋
5、復(fù)制生成正向和反向區(qū)域解析數(shù)據(jù)庫文件
[root@DNSserver ~]# cd /var/named/
[root@DNSserver named]# ls
data dynamic named.ca named.empty named.localhost named.loopback slaves
[root@DNSserver named]# cp -a named.localhost moyu.zone
[root@DNSserver named]# cp -a named.loopback 172.16.23.arpa
6仔雷、編輯正向區(qū)域解析數(shù)據(jù)庫文件
[root@DNSserver named]# vim moyu.zone
$TTL 1D
@ IN SOA moyu.com. root.moyu.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS ns1.moyu.com.
A 127.0.0.1
AAAA ::1
ns1 A 172.16.23.137
www A 172.16.23.139
cloud A 172.16.23.139
7蹂析、編輯反向區(qū)域解析數(shù)據(jù)庫文件
[root@localhost named]# vim 172.16.23.arpa
$TTL 1D
@ IN SOA moyu.com. root.moyu.com. (
0 ; serial
1D ; refresh
1H ; retry
1W ; expire
3H ) ; minimum
NS ns1.moyu.com.
A 127.0.0.1
AAAA ::1
PTR localhost.
ns1 A 172.16.23.137
139 PTR www.moyu.com
139 PTR cloud.moyu.com
8、配置文件檢測
[root@DNSserver ~]# named-checkconf /etc/named.conf
[root@DNSserver ~]# named-checkconf /etc/named.rfc1912.zones
# 回車后碟婆,沒有報錯信息說明沒有錯誤
9电抚、正向和反向區(qū)域解析測試
[root@localhost named]# named-checkzone moyu.com /var/named/moyu.zone
zone moyu.com/IN: loaded serial 0
OK
[root@localhost named]# named-checkzone moyu.com /var/named/172.16.23.arpa
zone moyu.com/IN: loaded serial 0
OK
10、重啟DNS服務(wù)竖共,查看端口
[root@localhost named]# netstat -tunlp | grep named
tcp 0 0 172.16.23.137:53 0.0.0.0:* LISTEN 233261/named
tcp 0 0 127.0.0.1:53 0.0.0.0:* LISTEN 233261/named
tcp 0 0 127.0.0.1:953 0.0.0.0:* LISTEN 233261/named
tcp6 0 0 :::53 :::* LISTEN 233261/named
tcp6 0 0 ::1:953 :::* LISTEN 233261/named
udp 0 0 192.168.122.1:53 0.0.0.0:* 233261/named
udp 0 0 172.16.23.137:53 0.0.0.0:* 233261/named
udp 0 0 127.0.0.1:53 0.0.0.0:* 233261/named
udp6 0 0 :::53 :::* 233261/named
到這里DNS服務(wù)端搭建完成
以下是client 服務(wù)器的操作
1蝙叛、查看客戶端主機的IP(Centos7)
[root@localhost named]# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.23.139 netmask 255.255.255.0 broadcast 172.16.23.255
2、測試是否能與服務(wù)器端互通
[root@localhost ~]# ping -c 3 172.16.23.137
PING 172.16.23.137 (172.16.23.137) 56(84) bytes of data.
64 bytes from 172.16.23.137: icmp_seq=1 ttl=64 time=0.505 ms
64 bytes from 172.16.23.137: icmp_seq=2 ttl=64 time=0.282 ms
64 bytes from 172.16.23.137: icmp_seq=3 ttl=64 time=0.366 ms
--- 172.16.23.137 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.282/0.384/0.505/0.093 ms
3肘迎、安裝bind-utils包
[root@localhost ~]# rpm -ql nslookup
package nslookup is not installed
[root@dnsclient ~]# yum install -y bind-utils
[root@localhost ~]# rpm -qa | grep bind-utils
bind-utils-9.11.4-26.P2.el7_9.2.x86_64
4甥温、在客戶端 /etc/resolv.conf 加入服務(wù)端的DNS
[root@dnsclient ~]# vim /etc/resolv.conf
[root@dnsclient ~]# cat /etc/resolv.conf
[root@localhost ~]# cat /etc/resolv.conf
# Generated by NetworkManager
nameserver 172.16.23.137
nameserver 8.8.8.8
5、測試
[root@localhost ~]# nslookup www.moyu.com
Server: 172.16.23.137
Address: 172.16.23.137#53
Name: www.moyu.com
Address: 172.16.23.139
[root@localhost ~]# nslookup 172.16.23.139
139.23.16.172.in-addr.arpa name = cloud.moyu.com.23.16.172.in-addr.arpa.
139.23.16.172.in-addr.arpa name = www.moyu.com.23.16.172.in-addr.arpa.
完成妓布!