ubuntu16.04 搭建 dns 服务器

深碍√TFBOYSˉ_ 2022-06-06 03:17 350阅读 0赞

具体需求:部门管理中,有git服务器,部门管理系统的服务器,vpn 服务器等等,每一个访问都是用ip,这样很烦,不高大上,我想整成这样:git服务器:git.com 管理系统的服务器:mag.com… 的形式。

解决方法:新建一个虚拟机(这里是ubuntu 16.04 64位),搭建成一个dns服务器,然后让部门的每一台电脑的dns指向dns服务器,就可以了。

环境(都是ubuntu16.04 64位):我的git服务器: 10.10.3.155
管理系统所在的服务器:10.10.3.154
新建的dns服务器:10.10.3.153

现在开始搭建dns服务器(10.10.3.153)

1.更新环境,切换成root用户

  1. su root
  2. apt-get update

2.安装bind9

  1. apt-get install bind9

3.配置/etc/bind/named.conf.local 文件(服务器域解析文件)

  1. zone "mag.com"{
  2. type master;
  3. file "db.mag.com";
  4. };
  5. zone "git.com"{
  6. type master;
  7. file "db.git.com";
  8. };

4.步骤3中的db.mag.com和db.git.com是域解析文件,默认在/etc/var/cache/bind,它们的格式与bind9自带的模板db.local格式一致,我们把/etc/bind/db.local文件copy到/etc/var/cache/bind下,并命名为db.mag.com 和 db.git.com

  1. cp /etc/bind/db.local /var/cache/bind/db.mag.com
  2. cp /etc/bind/db.local /var/cache/bind/db.git.com

5.编辑域解析文件

  1. vim /var/cache/bind/db.mag.com

在末尾加:@ IN A 10.10.3.154

即:

  1. ;
  2. ; BIND data file for local loopback interface
  3. ;
  4. $TTL 604800
  5. @ IN SOA localhost. root.localhost. (
  6. 2 ; Serial
  7. 604800 ; Refresh
  8. 86400 ; Retry
  9. 2419200 ; Expire
  10. 604800 ) ; Negative Cache TTL
  11. ;
  12. @ IN NS localhost.
  13. @ IN A 127.0.0.1
  14. @ IN AAAA ::1
  15. @ IN A 10.10.3.154

db.git.com 的配置同理,在/var/cache/bind/db.git.com 最后面加一句@ IN A 10.10.3.155 即可。

6.配置/etc/bind/named.conf.options 文件

在中间加入下面的代码,dns服务器就可以访问外网了

  1. forwarders { 8.8.8.8; };

完整的文件如下:

  1. options {
  2. directory "/var/cache/bind";
  3. // If there is a firewall between you and nameservers you want
  4. // to talk to, you may need to fix the firewall to allow multiple
  5. // ports to talk. See http://www.kb.cert.org/vuls/id/800113
  6. // If your ISP provided one or more IP addresses for stable
  7. // nameservers, you probably want to use them as forwarders.
  8. // Uncomment the following block, and insert the addresses replacing
  9. // the all-0's placeholder.
  10. // forwarders {
  11. // 0.0.0.0;
  12. // };
  13. forwarders {
  14. 8.8.8.8;
  15. };
  16. //========================================================================
  17. // If BIND logs error messages about the root key being expired,
  18. // you will need to update your keys. See https://www.isc.org/bind-keys
  19. //========================================================================
  20. dnssec-validation auto;
  21. auth-nxdomain no; # conform to RFC1035
  22. listen-on-v6 { any; };
  23. };

7.重启bind9服务

  1. /etc/init.d/bind9 restart

8.测试

这里写图片描述

在浏览器输入:git.com 回车

这里写图片描述

9.就这样成功了。

发表评论

表情:
评论列表 (有 0 条评论,350人围观)

还没有评论,来说两句吧...

相关阅读

    相关 Centos7DNS服务器

    Centos7搭建DNS服务器 Master DNS服务器:主DNS服务器。维护所负责解析的域内解析库服务器;解析库由管理员维护 Slaver DNS服务器:从DNS服务

    相关 linux中DNS服务器

    1.DNS全称为Domain Name System,即域名系统,其作用就是将我们经常使用的“网址”解析为IP地址 正向解析:根据域名(主机名)查找对应的IP地址 反向