LINUX学生会

Linux基础之DNS服务器第一篇

2017-07-28  本文已影响30人  数据革命

简介

DNS域名和DNS域名结构

名称 代表意义
com 公司、行号、企业
org 组织、机构
edu 教育单位
gov 政府单位
net 网络、通信
mil 军事单位

DNS原理

DNS解析

BIND等DNS软件

[root@localhost ~]# yum info bind
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Packages
Name        : bind
Arch        : x86_64
Epoch       : 32
Version     : 9.9.4    <<<版本
Release     : 37.el7
Size        : 1.8 M
Repo        : bash
Summary     : The Berkeley Internet Name Domain (BIND) DNS (Domain Name System) server
URL         : http://www.isc.org/products/BIND/   <<官方网站
License     : ISC
Description : BIND (Berkeley Internet Name Domain) is an implementation of the DNS
            : (Domain Name System) protocols. BIND includes a DNS server (named),
            : which resolves host names to IP addresses; a resolver library
            : (routines for applications to use when interfacing with DNS); and
            : tools for verifying that the DNS server is operating properly.
[root@localhost ~]# yum info unbound
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Packages
Name        : unbound
Arch        : x86_64
Version     : 1.4.20   <<版本
Release     : 28.el7
Size        : 473 k
Repo        : bash
Summary     : Validating, recursive, and caching DNS(SEC) resolver
URL         : http://www.nlnetlabs.nl/unbound/   <<官方网站
License     : BSD
Description : Unbound is a validating, recursive, and caching DNS(SEC) resolver.
            : 
            : The C implementation of Unbound is developed and maintained by NLnet
            : Labs. It is based on ideas and algorithms taken from a java prototype
            : developed by Verisign labs, Nominet, Kirei and ep.net.
            : 
            : Unbound is designed as a set of modular components, so that also
            : DNSSEC (secure DNS) validation and stub-resolvers (that do not run
            : as a server, but are linked into an application) are easily possible.
[root@localhost ~]# yum info dnsmasq
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
Name        : dnsmasq
Arch        : x86_64
Version     : 2.66
Release     : 21.el7
Size        : 464 k
Repo        : installed
From repo   : anaconda
Summary     : A lightweight DHCP/caching DNS server
URL         : http://www.thekelleys.org.uk/dnsmasq/
License     : GPLv2
Description : Dnsmasq is lightweight, easy to configure DNS forwarder and DHCP server.
            : It is designed to provide DNS and, optionally, DHCP, to a small network.
            : It can serve the names of local machines which are not in the global
            : DNS. The DHCP server integrates with the DNS server and allows machines
            : with DHCP-allocated addresses to appear in the DNS with names configured
            : either in each host or in a central configuration file. Dnsmasq supports
            : static and dynamic DHCP leases and BOOTP for network booting of diskless
            : machines.

DNS服务器搭建

[root@localhost ~]# yum -y install bind
Total                                                                                                                                                         20 MB/s | 2.8 MB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 32:bind-libs-9.9.4-37.el7.x86_64                                                                                                                                          1/2 
  Installing : 32:bind-9.9.4-37.el7.x86_64                                                                                                                                               2/2 
  Verifying  : 32:bind-9.9.4-37.el7.x86_64                                                                                                                                               1/2 
  Verifying  : 32:bind-libs-9.9.4-37.el7.x86_64                                                                                                                                          2/2 

Installed:
  bind.x86_64 32:9.9.4-37.el7                                                                                                                                                                

Dependency Installed:
  bind-libs.x86_64 32:9.9.4-37.el7                                                                                                                                                           

Complete!
[root@localhost ~]# rpm -ql bind
/etc/logrotate.d/named
/etc/named
/etc/named.conf     <<配置文件
/etc/named.iscdlv.key
/etc/named.rfc1912.zones
/etc/named.root.key
/etc/rndc.conf  
/etc/rndc.key
/etc/rwtab.d/named
/etc/sysconfig/named
/run/named
/usr/lib/systemd/system/named-setup-rndc.service
/usr/lib/systemd/system/named.service
/usr/lib/tmpfiles.d/named.conf
/usr/lib64/bind
/usr/libexec/generate-rndc-key.sh
/usr/sbin/arpaname
/usr/sbin/ddns-confgen
/usr/sbin/dnssec-checkds
/usr/sbin/dnssec-coverage
/var/log/named.log   <<日志
/var/log/named.log
/var/named
/var/named/data
/var/named/dynamic
/var/named/named.ca   << 世界十三个根服务器地址
/var/named/named.empty
/var/named/named.localhost
/var/named/named.loopback
/var/named/slaves


;; ADDITIONAL SECTION:
a.root-servers.net. 3600000 IN  A   198.41.0.4   <<ipv4地址 这个地址在美国,可以把IP粘贴到百度上可以查出来
a.root-servers.net. 3600000 IN  AAAA    2001:503:ba3e::2:30   <<ipv6地址
b.root-servers.net. 3600000 IN  A   192.228.79.201
c.root-servers.net. 3600000 IN  A   192.33.4.12
d.root-servers.net. 3600000 IN  A   199.7.91.13
d.root-servers.net. 3600000 IN  AAAA    2001:500:2d::d
e.root-servers.net. 3600000 IN  A   192.203.230.10
f.root-servers.net. 3600000 IN  A   192.5.5.241
f.root-servers.net. 3600000 IN  AAAA    2001:500:2f::f
g.root-servers.net. 3600000 IN  A   192.112.36.4
h.root-servers.net. 3600000 IN  A   128.63.2.53
h.root-servers.net. 3600000 IN  AAAA    2001:500:1::803f:235
i.root-servers.net. 3600000 IN  A   192.36.148.17
i.root-servers.net. 3600000 IN  AAAA    2001:7fe::53
j.root-servers.net. 3600000 IN  A   192.58.128.30
j.root-servers.net. 3600000 IN  AAAA    2001:503:c27::2:30
k.root-servers.net. 3600000 IN  A   193.0.14.129
k.root-servers.net. 3600000 IN  AAAA    2001:7fd::1
l.root-servers.net. 3600000 IN  A   199.7.83.42
l.root-servers.net. 3600000 IN  AAAA    2001:500:3::42
m.root-servers.net. 3600000 IN  A   202.12.27.33
m.root-servers.net. 3600000 IN  AAAA    2001:dc3::35
[root@localhost ~]# systemctl  enable named
Created symlink from /etc/systemd/system/multi-user.target.wants/named.service to /usr/lib/systemd/system/named.service.
[root@localhost ~]# ss -nutl
Netid State      Recv-Q Send-Q                                               Local Address:Port                                                              Peer Address:Port              
udp   UNCONN     0      0                                                                *:15562                                                                        *:*                  
udp   UNCONN     0      0                                                        127.0.0.1:53                                                                           *:*                  
udp   UNCONN     0      0                                                                *:68                                                                           *:*                  
udp   UNCONN     0      0                                                              ::1:53                                                                          :::*                  
udp   UNCONN     0      0                                                               :::10338                                                                       :::*                  
tcp   LISTEN     0      10                                                       127.0.0.1:53                                                                           *:*                  
tcp   LISTEN     0      128                                                              *:22                                                                           *:*                  
tcp   LISTEN     0      128                                                      127.0.0.1:953                                                                          *:*                  
tcp   LISTEN     0      100                                                      127.0.0.1:25                                                                           *:*                  
tcp   LISTEN     0      10                                                             ::1:53                                                                          :::*                  
tcp   LISTEN     0      128                                                             :::22                                                                          :::*                  
tcp   LISTEN     0      128                                                            ::1:953                                                                         :::*                  
tcp   LISTEN     0      100                                                            ::1:25                                                                          :::*    
[root@localhost ~]# telnet 172.16.253.8 53 
Trying 172.16.253.8...
telnet: connect to address 172.16.253.8: Connection refused   <<链接拒绝的意思
[root@localhost ~]# ll /etc/named.conf 
-rw-r-----. 1 root named 1705 Mar 22  2016 /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 { 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; };

        /* 
         - 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. 
         - If your recursive DNS server has a public IP address, you MUST enable access 
           control to limit queries to your legitimate users. Failing to do so will
           cause your server to become part of large scale DNS amplification 
           attacks. Implementing BCP38 within your network would greatly
           reduce such attack surface 
        */
        recursion yes;

        dnssec-enable yes;
        dnssec-validation yes;

        /* Path to ISC DLV key */
        bindkeys-file "/etc/named.iscdlv.key";

        managed-keys-directory "/var/named/dynamic";
[root@localhost ~]# ss -nutl
Netid State      Recv-Q Send-Q                                               Local Address:Port                                                              Peer Address:Port              
udp   UNCONN     0      0                                                                *:15562                                                                        *:*                  
udp   UNCONN     0      0                                                     172.16.253.8:53                                                                           *:*                  
udp   UNCONN     0      0                                                        127.0.0.1:53                                                                           *:*                  
udp   UNCONN     0      0                                                                *:68                                                                           *:*                  
udp   UNCONN     0      0                                                              ::1:53                                                                          :::*                  
udp   UNCONN     0      0                                                               :::10338                                                                       :::*                  
tcp   LISTEN     0      10                                                    172.16.253.8:53                                                                           *:*                  
tcp   LISTEN     0      10                                                       127.0.0.1:53                                                                           *:*                  
tcp   LISTEN     0      128                                                              *:22                                                                           *:*                  
tcp   LISTEN     0      128                                                      127.0.0.1:953                                                                          *:*                  
tcp   LISTEN     0      100                                                      127.0.0.1:25                                                                           *:*                  
tcp   LISTEN     0      10                                                             ::1:53                                                                          :::*                  
tcp   LISTEN     0      128                                                             :::22                                                                          :::*                  
tcp   LISTEN     0      128                                                            ::1:953                                                                         :::*                  
tcp   LISTEN     0      100                                                            ::1:25                                                                          :::*  
[root@localhost ~]# telnet 172.16.253.8 53 
Trying 172.16.253.8...
Connected to 172.16.253.8.
Escape character is '^]'.
上一篇 下一篇

猜你喜欢

热点阅读