搭建简单的本地DNS服务

搭建本地dns解析环境,用作本地web开发调试环境
系统自带的hosts解析(/etc/hosts)不支持泛解析(*.domain.com)

安装札记

安装域名服务器bind9和相关工具

sudo aptitude install bind9 dnsutils

修改配置文件,named.conf.local是本地环境的配置文件

sudo vi /etc/bind/named.conf.local
加入

1
2
3
4
5
6
7
8
9
zone "wordpress.mu" IN {
type master;
file "/etc/bind/wordpress.mu";
};

zone "1.1.127.in-addr.arpa" IN {
type master;
file "/etc/bind/wordpress.mu";
};

sudo vi /etc/bind/wordpress.mu

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
;
; BIND reverse data file for local loopback interface
;
$TTL    86400
@       IN      SOA     wordpress.mu. root.localhost. (
1         ; Serial
604800         ; Refresh
86400         ; Retry
2419200         ; Expire
86400)        ; Negative Cache TTL
;
@       IN      NS      www
@       IN      A       127.0.0.1
*       IN      A       127.0.0.1
120     IN      PTR     www.wordpress.mu
120     IN      PTR     *.wordpress.mu

更改你机器的dns服务器ip

sudo vi /etc/resolv.conf

1
nameserver 127.0.0.1

重启bind9服务

sudo /etc/init.d/bind9 restart

看看是否生效

alex@alex-laptop:~$ nslookup
> wordpress.mu
Server: 127.0.0.1
Address: 127.0.0.1#53

Name: wordpress.mu
Address: 127.0.0.1
> whatever.wordpress.mu
Server: 127.0.0.1
Address: 127.0.0.1#53

Name: whatever.wordpress.mu
Address: 127.0.0.1
>

完成

Share and Enjoy:
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
This entry was posted in Technologies and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>