如今的公司每一個都應該有本身的網站(若是公司沒有本身的網站,那也不用在那裏待了,浪費青春),訪問網站的時候不可能給個192.168.1.1去訪問去,因此DNS在如今公司中佔有舉足輕重的做用:而且它還有個緩存服務器的做用,可以加快公司員工的上網速度,那麼配置一個DNS服務器要多長時間呢? 標準從開始作到結束30秒,腳本輕鬆搞定DNS服務器。怎麼簡單怎麼來麼。以最短的時間作出作多的事這纔是好員工麼。廢話很少說,開始作。
配置環境。一臺linux系統服務器,Red Hat 企業版5 一張Red Hat 企業版5光盤(提早插到光驅中等下要掛載東西)
#!/bin/bash
mkdir /mafei
mount /dev/cdrom /mafei
cd /mafei/Server
rpm -e `rpm -qa | grep ^bind` --nodeps --force
rpm -ivh bind-* --nodeps --force
rpm -ivh caching-nameserver-9.3.3-7.el5.i386.rpm
echo "search server.mafei.com" > /etc/resolv.conf
echo "nameserver 192.168.142.128" >> /etc/resolv.conf
cd /var/named/chroot/etc/
vi /var/named/chroot/etc/named.caching-nameserver.conf << MAFEI
:%s/127.0.0.1/any/g
:%s/localhost/any/g
:wq
MAFEI
echo 'zone "mafei.com" IN { type master; file "mafei.com"; };' >> /var/named/chroot/etc/named.rfc1912.zones
cd /var/named/chroot/var/named/
cp named.local mafei.com
vi /var/named/chroot/var/named/mafei.com << MAFEIFEI
:%s/1 IN PTR localhost./www IN A 192.168.142.128/g
:wq
MAFEIFEI
bind-chroot-admin -s
service named restart
ping www.mafei.com
|
若是想一步步作的話下面可供參考。具體有正向解析,反向解析,以及不一樣域名同一IP等的配置實例,首先作一個正向,若是正向都沒作出來那麼後面的也不用作了。
配置IP子網掩碼。以及DNS
[root@server ~]# vi /etc/sysconfig/network-scripts/ifcfg-eth0
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
DEVICE=eth0
HWADDR=00:0c:29:c1:ef:7f
ONBOOT=yes
IPADDR=192.168.142.2
NETMASK=255.255.255.0
TYPE=Ethernet
|
[root@server ~]# vi /etc/resolv.conf
search mafei.com
nameserver 192.168.142.2
|
將光盤掛載到/mafei下。並刪除原來的DNS軟件包
[root@server ~]# mkdir /mafei
[root@server ~]# mount /dev/cdrom /mafei
mount: block device /dev/cdrom is write-protected, mounting read-only
[root@server ~]# cd /mafei/Server/
[root@server Server]# rpm -e `rpm -qa | grep ^bind` --nodeps
warning: /etc/sysconfig/named saved as /etc/sysconfig/named.rpmsave
/var/tmp/rpm-tmp.51087: line 2: /usr/sbin/bind-chroot-admin: No such file or directory
error: %preun(bind-chroot-9.3.3-7.el5.i386) scriptlet failed, exit status 1
|
從光盤中安裝DNS服務器必備的兩大軟件包
其中bind軟件包是DNS服務器的配置軟件包
至於caching軟件包麼。裏面提供了DNS服務配置的模板你牛的話也能夠不用本身寫
[root@server Server]# rpm -ivh bind-* --nodeps --force
warning: bind-9.3.3-7.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:bind-utils ########################################### [ 14%]
2:bind ########################################### [ 29%]
3:bind-chroot ########################################### [ 43%]
4:bind-devel ########################################### [ 57%]
5:bind-libbind-devel ########################################### [ 71%]
6:bind-libs ########################################### [ 86%]
7:bind-sdb ########################################### [100%]
[root@server Server]# rpm -ivh caching-nameserver-9.3.3-7.el5.i386.rpm
warning: caching-nameserver-9.3.3-7.el5.i386.rpm: Header V3 DSA signature: NOKEY, key ID 37017186
Preparing... ########################################### [100%]
1:caching-nameserver ########################################### [100%]
|
進入DNS主目錄。修改主配置文件中選項。
其實說白了。就是將127.0.0.1該爲any
將localhost改成any就OK了。至於內容麼。。應該知道吧。
[root@server Server]# hostname
server.mafei.com
[root@server Server]# cd /var/named/chroot/etc/
[root@server etc]# ls
localtime named.caching-nameserver.conf named.rfc1912.zones rndc.key
[root@server etc]# vi named.caching-nameserver.conf
options {
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";
query-source port 53;
query-source-v6 port 53;
allow-query { any; };
};
logging {
channel default_debug {
file "data/named.run";
severity dynamic;
};
};
view any_resolver {
match-clients { any; };
match-destinations { any; };
recursion yes;
include "/etc/named.rfc1912.zones";
};
|
修改DNS的輔配置文件在最後加入要創建的域名
本文中要創建的域名爲mafei.com
注意: 在指定文件中的mafei.com雖然是自定義的文件名稱可是必須和後面的文件名稱相同不然會出錯。並且注意每一行後面都有;的,(我就在這裏栽過N次。。)
[root@server etc]# vi named.rfc1912.zones
zone "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.ip6.local";
allow-update { none; };
};
zone "255.in-addr.arpa" IN {
type master;
file "named.broadcast";
allow-update { none; };
};
zone "0.in-addr.arpa" IN {
type master;
file "named.zero";
allow-update { none; };
};
zone "mafei.com" IN {
type master;
file "mafei.com";
};
|
不是要作www.mafei.com啊。剛纔作了mafei.com如今來作下www(雖然叫起來不太專業但最起碼能聽懂、)
進入DNS的主機目錄,這裏有配置的模板咱們只須要拷貝一份過來再進行修改就OK
此處我拷了一份模板過來名字爲mafei.com (注意要和剛纔的文件名要相同。)
在後面一行添加一條主機的A記錄就行。讓主機可以對應相應的IP
[root@server etc]# vi named.rfc1912.zones
[root@server etc]# cd ../var/named/
[root@server named]# ls
data localhost.zone named.ca named.local slaves
localdomain.zone named.broadcast named.ip6.local named.zero
[root@server named]# cp named.local mafei.com
[root@server named]# vi mafei.com
$TTL 86400
@ IN SOA localhost. root.localhost. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS localhost.
www IN A 192.168.142.2
|
由於作完以後各個文件的權限的問題因此得用Bind-chroot-admin –s 進行權限的自動化配置
作完以後重啓下named 服務便可用了
[root@server named]# bind-chroot-admin –s
[root@server etc]# service named restart
Stopping named: [FAILED]
Starting named: [ OK ]
[root@server etc]# ping www.mafei.com
PING www.mafei.com (192.168.142.2) 56(84) bytes of data.
64 bytes from 192.168.142.2: icmp_seq=1 ttl=64 time=0.027 ms
64 bytes from 192.168.142.2: icmp_seq=2 ttl=64 time=0.028 ms
64 bytes from 192.168.142.2: icmp_seq=3 ttl=64 time=0.030 ms
--- www.mafei.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2001ms
rtt min/avg/max/mdev = 0.027/0.028/0.030/0.004 ms
|
至於作DNS的反向解析,以及同一IP不一樣主機,只要前面作好了。後面只須要。添加相應的域名記錄和主機記錄便可,,其實都有模板只要照着上面模板抄一遍就OK了。不用死記
1. 在DNS的輔助主文件中添加域名記錄。 (添加反向記錄時輸入的ip 爲服務器ip地址的後3位)
此處添加192.168.142.2 解析爲www.mafeifei.com
www.fei.com解析爲192.168.142.2(同一ip不一樣域名,)
[root@server etc]# vi named.rfc1912.zones
zone "mafei.com" IN {
type master;
file "mafei.com";
};
zone "142.168.192.in-addr.arpa" IN {
type master;
file "mafeifei.com";
};
zone "fei.com" IN {
type master;
file "fei.com";
};
|
2. 設置主機記錄。
設置同一ip不一樣域名時由於剛纔作www.mafei.com時已經作過。此步仍是要解析爲www.fei.com 添加一條A記錄便可。因此此處再也不重複。直接複製一份。
設置反向域名解析時 仍是cp模板到mafeifei.com 設置記錄。格式爲
2: 此服務器ip爲192.168.142.2此處的2就是服務器的最後一位ip
PTR: 設置主機的反向解析。
www.mafeifei.com : 這個沒什麼說的就是要解析的域名
[root@server named]# cp mafei.com fei.com
[root@server named]# cp named.local mafeifei.com
[root@server named]# vi mafeifei.com
$TTL 86400
@ IN SOA localhost. root.localhost. (
1997022700 ; Serial
28800 ; Refresh
14400 ; Retry
3600000 ; Expire
86400 ) ; Minimum
IN NS localhost.
2 IN PTR www.mafeifei.com.
root@server named]# ls
data localhost.zone named.broadcast named.local
fei.com mafei.com named.ca named.zero
localdomain.zone mafeifei.com named.ip6.local slaves
|
作完仍是老動做先作權限再重啓服務使配置生效
[root@server named]# bind-chroot-admin -s
[root@server named]# service named restart
Stopping named: [ OK ]
Starting named: [ OK ]
|
進行驗證
[root@server named]# nslookup
> www.mafei.com
Server: 192.168.142.2
Address: 192.168.142.2#53
Name: www.mafei.com
Address: 192.168.142.2
> www.fei.com
Server: 192.168.142.2
Address: 192.168.142.2#53
Name: www.fei.com
Address: 192.168.142.2
> 192.168.142.2
Server: 192.168.142.2
Address: 192.168.142.2#53
2.142.168.192.in-addr.arpa name = www.mafeifei.com.
|
好了,作到這裏恭喜你DNS服務器能夠對你說easy了 輕鬆搞定。