有时候给内网配置个DNS很方便,至少做起实验来可以随便搞域名不用担心冲突。

安装

1
apt-get install bind9

添加转发DNS为你的实际DNS

1
vim /etc/bind/named.conf.options
1
2
3
4
5
6
7
8
9
10
11
forwarders {

202.113.112.55;

202.113.112.45;

222.222.222.222;

8.8.8.8;

};
1
vim /etc/bind/named.conf.local

添加配置域

添加一个你自己的域及其反向域,比如我的是 myserver.com

1
2
3
4
5
6
7
8
zone "1.168.192.in-addr.arpa" {
type master;
file "/var/lib/bind/192.168.1.hosts";
};
zone "myserver.com" {
type master;
file "/var/lib/bind/myserver.com.hosts";
};

然后配置该域记录

1
vim /var/lib/bind/myserver.com.hosts

照葫芦画瓢,我的是这样的

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$ttl 38400
myserver.com. IN SOA dis. zhuhuaizhong.126.com. (
1342749713
10800
3600
604800
38400 )
myserver.com. IN NS dis.
www.myserver.com. IN A 192.168.1.2
www1.myserver.com. IN A 192.168.1.3
www2.myserver.com. IN A 192.168.1.4
www3.myserver.com. IN A 192.168.1.5
db.myserver.com. IN A 192.168.1.6
db1.myserver.com. IN A 192.168.1.7
db2.myserver.com. IN A 192.168.1.8
dbbak.myserver.com. IN A 192.168.1.9
static.myserver.com. IN A 192.168.1.10
staticbak.myserver.com. IN A 192.168.1.11
mem.myserver.com. IN A 192.168.1.12
dis.myserver.com. IN A 192.168.1.1
hdmanager.myserver.com. IN A 192.168.1.20
hdmaster.myserver.com. IN A 192.168.1.21
hdslaver1.myserver.com. IN A 192.168.1.22
hdslaver2.myserver.com. IN A 192.168.1.23
hdslaver3.myserver.com. IN A 192.168.1.24
hdslaver4.myserver.com. IN A 192.168.1.25
hdslaver5.myserver.com. IN A 192.168.1.26
hdslaver6.myserver.com. IN A 192.168.1.27
hdslaver7.myserver.com. IN A 192.168.1.28
hdslaver8.myserver.com. IN A 192.168.1.29
hdbackup.myserver.com. IN A 192.168.1.30

配置反向域记录:

1
vim /var/lib/bind/192.168.1.hosts

我的是这样的:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
$ttl 38400
@ IN SOA dis. zhuhuaizhong.126.com. (
1342749713
10800
3600
604800
38400 )
IN NS dis.
1 PTR dis.myserver.com.
2 PTR www.myserver.com.
3 PTR www1.myserver.com.
4 PTR www2.myserver.com.
5 PTR www3.myserver.com.
6 PTR db.myserver.com.
7 PTR db1.myserver.com.
8 PTR db2.myserver.com.
9 PTR dbbak.myserver.com.
10 PTR static.myserver.com.
11 PTR staticbak.myserver.com.
12 PTR mem.myserver.com.
20 PTR hdmanager.myserver.com.
21 PTR hdmaster.myserver.com.
22 PTR hdslaver1.myserver.com.
23 PTR hdslaver2.myserver.com.
24 PTR hdslaver3.myserver.com.
25 PTR hdslaver4.myserver.com.
26 PTR hdslaver5.myserver.com.
27 PTR hdslaver6.myserver.com.
28 PTR hdslaver7.myserver.com.
29 PTR hdslaver8.myserver.com.
30 PTR hdbackup.myserver.com.

服务的启动停止:

1
/etc/init.d/bind9 start|stop|restart