dns ubuntu 自动获取_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.com,ping www.baidu.com

后记

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值