Ubuntu14.04配置DNS Server

前言

《Ubuntu系统批量自动安装》一文中,也许会用到DNS Server,那么就来研究配置一下。

配置目标:在Ubuntu14.04上,搭建一个DNS服务器,服务器地址为10.0.0.100。使用这个DNS,可以把dns.voidking.com域名解析到10.0.0.100这个地址。

实践

安装

安装命令:
sudo apt-get update

sudo apt-get install bind9

安装完成后,会创建/etc/bind目录,里面有很多配置文件。

DNS正反解区域

1、添加DNS正反解区域,需要修改named.conf.default-zones

sudo vim /etc/bind/named.conf.default-zones,在最后添加:

zone "voidking.com" {
        type master;
        file "/etc/bind/db.voidking.com";
};

zone "0.0.10.in-addr.arpa" {
        type master;
        file "/etc/bind/db.10.0.0";
};

添加正解区域“voidking.com”,以及反解区域“10.0.0.0”

2、创建db.voidking.com并编辑
cd /etc/bind
sudo cp db.local db.voidking.com
sudo vim db.voidking.com

添加一个A记录到10.0.0.100:

;
; BIND data file for local loopback interface
;
$TTL    604800
@       IN      SOA     localhost. root.localhost. (
                              2         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      localhost.
@       IN      A       127.0.0.1
@       IN      AAAA    ::1
dns     IN      A       10.0.0.100

3、创建db.10.0.0并编辑
sudo cp db.127 db.10.0.0
sudo vim db.10.0.0

添加100的反向解析到dns.voidking.com:

;
; BIND reverse data file for local loopback interface
;
$TTL    604800
@       IN      SOA     localhost. root.localhost. (
                              1         ; Serial
                         604800         ; Refresh
                          86400         ; Retry
                        2419200         ; Expire
                         604800 )       ; Negative Cache TTL
;
@       IN      NS      voidking.com.
100     IN      PTR     dns.voidking.com.

测试

1、测试访问
ping dns.voidking.com
这次访问会提示 connection timed out: no servers could be reached,或者提示 ping: unknown host dns.voidking.com

2、重启dns服务
sudo /etc/init.d/bind9 restart

3、测试访问
ping dns.voidking.com
这次访问,就可以正常ping到服务器100的ip地址。

host 10.0.0.100,可以看到10.0.0.100绑定到了dns.voidking.com。

至此,DNS服务器已经配置成功。但是,我们本地的这个DNS服务器上存的域名太少了,比如ping www.baidu.com,就会ping不通。这时,我们需要配置转发服务器。

配置转发服务器

1、编辑named.conf.options
sudo vim named.conf.options

forwarders设置转发DNS为180.76.76.76,allow-query设置为0.0.0.0/0:

options {
        directory "/var/cache/bind";

        // If there is a firewall between you and nameservers you want
        // to talk to, you may need to fix the firewall to allow multiple
        // ports to talk.  See http://www.kb.cert.org/vuls/id/800113

        // If your ISP provided one or more IP addresses for stable
        // nameservers, you probably want to use them as forwarders.
        // Uncomment the following block, and insert the addresses replacing
        // the all-0's placeholder.

        forwarders {
                180.76.76.76;
        };

        allow-query {
                0.0.0.0/0;
        };

        //========================================================================
        // If BIND logs error messages about the root key being expired,
        // you will need to update your keys.  See https://www.isc.org/bind-keys
        //========================================================================
        dnssec-validation auto;

        auth-nxdomain no;    # conform to RFC1035
        listen-on-v6 { any; };
};

2、重启DNS服务
sudo /etc/init.d/bind9 restart

3、测试访问
ping www.baidu.com

4、其他机器测试访问
同局域网主机在/etc/resolv.conf中添加:

nameserver 10.0.0.100

然后ping dns.voidking.comping www.baidu.com

后记

至此,DNS Server安装配置成功,更高级的用法需要时再去学习。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

  • 1. 概述 在网络环境中一般用户只需要在浏览器中输入url如www.sunny.com就可以到对应服务器获取相应的...
    ghbsunny阅读 3,522评论 0 7
  • 一、实现从根,com,rj.com 模拟互联网的DNS架构 DNS(Domain Name System,域名系统...
    ssjinyao阅读 1,656评论 0 7
  • 一、BIND是什么 BIND是互联网应用最为广泛的DNS软件。 二、BIND的安装与使用 以下内容转自 http:...
    0_0啊阅读 3,431评论 0 0
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 137,150评论 19 139
  • Ubuntu的发音 Ubuntu,源于非洲祖鲁人和科萨人的语言,发作 oo-boon-too 的音。了解发音是有意...
    萤火虫de梦阅读 101,055评论 9 468

友情链接更多精彩内容