超简单步骤搭建公用DNS

  • A+
所属分类:运维教程

学过网络基础的同学都知道,我们要想在网络中通信,必须依赖ip地址才可以。而ip地址的记忆成本有些大,所以在浏览网站时,我们一般会通过域名来访问。网络中有个叫DNS的服务,为我们提供域名解析的功能,将域名解析到对应的IP地址。网络中的DNS服务非常多,这些DNS服务器我们一般称之为Public DNS,中文名为公共DNS服务器。

为什么有那么多的Public DNS呢?一个原因是解决负载的问题,还有一个是做访问限制。什么是访问限制呢?简单来说就是不允许你访问某些网站,方法非常简单,将请求的域名,对应到一个不可访问的IP地址上即可,就像我们平时访问不了谷歌,就是这个原因。如何突破这种限制?一个是通过静态解析文件hosts实现,还有一个就是搭建一个属于自己的公用DNS。

下面我们用最简单步骤搭建一台公用的DNS。这里以CentOS6为例,小版本不限制。

首先安装服务,安装的命令大家都知道,直接yum就行了,命令如下:

  1. yum -y install bind-*

成功之后的效果图如下:

超简单步骤搭建公用DNS

有同学可能注意到,这里我们安装了bind-chroot,这是安全性的增强工具,会把本地的服务根目录限制在/var/chroot,因为我们要做公共DNS服务器,也就是说,可以提供给你身边的人使用,会公布在互联网中,安全问题当然也是我们要考虑的。

然后编写配置文件,CentOS6的配置文件在/etc/named.conf,使用vim命令修改就行了,命令如下:

  1. vim /etc/named.conf

将listen-on port 53 { 127.0.0.1; };删除即可。

最后启动服务:

  1. service named start
  2. #启动服务
  3. chkconfig named on
  4. #开机启动

如果主机开启了防火墙,还需要打开DNS的端口53,参考命令如下:

  1. iptables -A INPUT -p all --dport 53 -j ACCEPT

DNS使用TCP/UDP的53端口,所以需要同时打开,最后我们测试一下,看看效果:

超简单步骤搭建公用DNS

原理:bind服务安装后,默认配置为缓存服务器模式。在请求域名时,会自动询去问根服务器,然后通过迭代查询,确认最终解析地址,返回给客户端同时,在本地会保留一份,已备再次查询。

  • 问答中心
  • 微信小程序扫一扫
  • weinxin
  • 微信公众
  • 微信公众号扫一扫
  • weinxin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

目前评论:28   其中:访客  28   博主  0

    • avatar cbd oil that works 2020

      Very descriptive article, I liked that a lot.
      Will there be a part 2?

      • avatar cbd oil that works 2020

        When I initially commented I clicked the “Notify me when new comments are added” checkbox and now
        each time a comment is added I get several emails with the same comment.
        Is there any way you can remove people from that service?

        Thanks a lot!

        • avatar cbd oil that works 2020

          An outstanding share! I have just forwarded this onto a coworker who
          was conducting a little homework on this.
          And he in fact ordered me dinner because I found it for him…
          lol. So let me reword this…. Thanks for the meal!!
          But yeah, thanks for spending time to talk about this issue here
          on your web page.

          • avatar cbd oil that works 2020

            Hi, constantly i used to check webpage posts here early in the break of day, as i enjoy to find out more and more.

            • avatar site here

              Keep functioning ,splendid job!

              • avatar cbd oil that works 2020

                I think this is one of the most vital info
                for me. And i am glad reading your article. But wanna remark on some general things,
                The site style is perfect, the articles is really great : D.
                Good job, cheers

                • avatar hxjyl.com

                  I’m not sure exactly why but this web site is loading extremely slow for me.
                  Is anyone else having this problem or is it a issue
                  on my end? I’ll check back later on and see if the problem still exists.

                  • avatar http://tinyurl.com/

                    That is a great tip particularly to those new to the blogosphere.
                    Brief but very accurate information… Appreciate your sharing this one.
                    A must read post!