由於公司內部網路需要做測試,採用網域名稱訪問公司內網伺服器。可是路由器不帶有網域名稱轉寄的功能,於是乎,就想到了採用DNS的方式。
背景:
公司內部伺服器一台:
系統:CentOS6.5_x64
hostname:server.andy.local
IP:192.168.10.10
1、安裝bind服務
yum -y install bind*
2、配置DNS Server,以下所有藍色地方都是修改的。
vim /etc/named.conf
//
// named.conf
//
// Provided by Red Hat bind package to configure the ISC BIND named(8) DNS
// server as a caching only nameserver (as a localhost DNS resolver only).
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
options {
// listen-on port 53 { 127.0.0.1; };
listen-on port 53 { any; };
listen-on-v6 port 53 { ::1; };
directory "/var/named";
dump-file "/var/named/data/cache_dump.db";
statistics-file "/var/named/data/named_stats.txt";
memstatistics-file "/var/named/data/named_mem_stats.txt";
// allow-query { localhost; };
allow-query { any; };
recursion yes;
dnssec-enable yes;
dnssec-validation yes;
dnssec-lookaside auto;
/* Path to ISC DLV key */
bindkeys-file "/etc/named.iscdlv.key";
managed-keys-directory "/var/named/dynamic";
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
zone "." IN {
type hint;
file "named.ca";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
———————————–
vim /etc/named.rfc1912.zones
// named.rfc1912.zones:
//
// Provided by Red Hat caching-nameserver package
//
// ISC BIND named zone configuration for zones recommended by
// RFC 1912 section 4.1 : localhost TLDs and address zones
// and http://www.ietf.org/internet-drafts/draft-ietf-dnsop-default-local-zones-02.txt
// (c)2007 R W Franks
//
// See /usr/share/doc/bind*/sample/ for example named configuration files.
//
zone "localhost.localdomain" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "localhost" IN {
type master;
file "named.localhost";
allow-update { none; };
};
zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};
zone "1.0.0.127.in-addr.arpa" IN {
type master;
file "named.loopback";
allow-update { none; };
};
zone "0.in-addr.arpa" IN {
type master;
file "named.empty";
allow-update { none; };
};
zone "andy.local" IN {
type master;
file "named.andy.local";
allow-update { none; };
};
zone "xxxx.com" IN {
type master;
file "named.xxxx.com";
allow-update { none; };
};
一定要注意每句後面都有個分號;
3、添加DNS本機正向解析檔案
vim /var/named/named.andy.local
$TTL 86400
@ IN SOA server.andy.local. root.andy.local. (
2015080700 ;(序號)每次更新都要+1
3600 ;(更新頻率)從伺服器向主伺服器要求更新時間
1800 ;(失敗重新嘗試時間)通常為更新頻率的一半
604800 ;(失效時間)一直失敗嘗試時間限定
86400 ;(快取時間)可以理解為預設TTL時間
)
@ IN NS server.andy.local.
@ IN A 192.168.10.10
server IN A 192.168.10.10
ns IN A 192.168.10.10
添加xxxx網域名稱解析檔案
vim /var/named/named.xxxx.com
$TTL 86400
@ IN SOA ns.andy.local. root.andy.local. (
2015080700 ;(序號)每次更新都要+1
3600 ;(更新頻率)從伺服器向主伺服器要求更新時間
1800 ;(失敗重新嘗試時間)通常為更新頻率的一半
604800 ;(失效時間)一直失敗嘗試時間限定
86400 ;(快取時間)可以理解為預設TTL時間
)
@ IN NS ns.andy.local.
@ IN A 192.168.10.10
www IN A 192.168.10.10
user IN A 192.168.10.10
admin IN A 192.168.10.10
然後啟動dns server
/etc/init.d/named start
// 開機啟動
chkconfig named on
然後在路由器上配置第一個DNS 地址為:192.168.10.10
第二個DNS地址為正常的DNS地址。
這樣,公司內部訪問特定的xxxx.com網域名稱,就會解析到內部伺服器。同時還可以訪問外網。
dig xxxx.com
; <<>> DiG 9.8.3-P1 <<>> xxxx.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 61174
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1
;; QUESTION SECTION:
;xxxx.com. IN A
;; ANSWER SECTION:
xxxx.com. 86400 IN A 192.168.10.10
;; AUTHORITY SECTION:
xxxx.com. 86400 IN NS ns.andy.local.
;; ADDITIONAL SECTION:
ns.andy.local. 86400 IN A 192.168.10.10
;; Query time: 30 msec
;; SERVER: 192.168.10.10#53(192.168.10.10)
;; WHEN: Thu Sep 3 18:04:09 2015
;; MSG SIZE rcvd: 86
一般情況加,DNS伺服器會做一個主/從模式,還需要反解析檔案。這裡主要公司自我裝載使用,就沒有做更多的東西。大家可以自行搜尋。。。