Linux下搭建DNS服务器

本文详细介绍了如何在Ubuntu 12.04上搭建DNS服务器,包括安装BIND9、配置正向与反向解析以及重启服务等步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Linux下搭建DNS服务器


2017/2/7 9:58:13 上海长宁
记录一下自己搭建DNS服务器的过程


  • 服务器宿主机:系统(Ubuntu12.04-32bit)IP(10.10.20.11)子网掩码(255.255.255.0)
  • 要求解析:(www.dzc.com == 10.10.20.11)(test.dzc.com == 10.10.20.12)

安装DNS服务器工具包

Linux下的DNS服务器通常使用 bind9 来搭建。

  • 在线安装:apt-get install bind9
  • 离线安装:
    1. 下载 bind9 deb安装包及其依赖包,附下载地址:
    2. 复制所有deb包到宿主机/var/cache/apt/archives/
    3. 运行apt-get install -f *.deb。
  • 安装之后,在/etc/目录下有bind/目录
    ll /etc/bind/
    drwxr-xr-x 2 root root 4096 8月 18 11:39 ./
    drwxr-xr-x 130 root root 12288 8月 18 11:51 ../
    -rwxr-xr-x 1 root root 2389 8月 15 16:43 bind.keys*
    -rwxr-xr-x 1 root root 237 8月 15 16:43 db.0*
    -rwxr-xr-x 1 root root 271 8月 15 16:43 db.127*
    -rwxr-xr-x 1 root root 237 8月 15 16:43 db.255*
    -rwxr-xr-x 1 root root 353 8月 15 16:43 db.empty*
    -rwxr-xr-x 1 root root 270 8月 15 16:43 db.local*
    -rwxr-xr-x 1 root root 2994 8月 15 16:43 db.root*
    -rwxr-xr-x 1 root root 463 8月 15 16:43 named.conf*
    -rwxr-xr-x 1 root root 490 8月 15 16:43 named.conf.default-zones*
    -rwxr-xr-x 1 root root 327 8月 15 16:43 named.conf.local*
    -rwxr-xr-x 1 root root 890 8月 15 16:43 named.conf.options*
    -rwxr-xr-x 1 root root 77 8月 15 16:43 rndc.key*
    -rwxr-xr-x 1 root root 1317 8月 15 16:43 zones.rfc1918*

配置DNS服务器

  • 进入/etc/bind/目录,修改name.conf.local文件。
//
// Do any local configuration here
//
// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";
zone "dzc.com" {
type master;
file "/etc/bind/db.dzc.com";
};
zone "20.10.10.in-addr.arpa" {
type master;
notify no;
file "/etc/bind/db.20.10.10.in-addr.arpa";
};
  1. 添加了正向域 dzc.com 和对应文件 /etc/bind/db.dzc.com
  2. 添加了反向域 20.10.10.in-addr.arpa 和对应文件 /etc/bind/db.20.10.10.in-addr.arpa
  3. 反向域的命名规则是到这些的IP地址。

修改域文件

注意:在修改正向域和反向域文件时,不使用空格,而应该使用TAB键隔开。域名后有个点,不要忘了。

  • 配置正向解析域:vim db.dzc.com
    复制正向域模板文件 db.local 并改名为 db.dzc.com 。
;
; BIND data file for local loopback interface
;
$TTL   604800
@   IN  SOA dzc.com. root.dzc.com. (
                  2     ; Serial
             604800     ; Refresh
              86400     ; Retry
            2419200     ; Expire
             604800 )   ; Negative Cache TTL
;
@   IN  NS  dzc.com.
@   IN  A   127.0.0.1
@   IN  AAAA    ::1
www IN  A   10.10.20.11
test    IN  A   10.10.20.12
  • 配置反向解析域:vim db.20.10.10.in-addr.arpa
    复制反向域模板文件 db.127 并改名为 db.20.10.10.in-addr.arpa 。
;
; BIND reverse data file for local loopback interface
;
$TTL   604800
@   IN  SOA dzc.com. root.dzc.com. (
                  1     ; Serial
             604800     ; Refresh
              86400     ; Retry
            2419200     ; Expire
             604800 )   ; Negative Cache TTL
;
@   IN  NS  dzc.com.
1.0.0   IN  PTR localhost.
11  IN  PTR www.dzc.com.
12  IN  PTR test.dzc.com.
  • 重启DNS服务器:service bind9 restart
  • 配置客户机的DNS服务器为宿主机的ip:10.10.20.11
  • 在服务器更改重启后,所有客户机应当重启网卡或清空DNS缓存。win10系统特别注意,有时候重启网卡无效,必须清空DNS缓存。在cmd命令行窗口下,输入:ipconfig /?系统会列出包含DNS的各项指令。ipconfig /dispalydns (显示DNS记录)ipconfig /flushdns(清空DNS缓存)。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值