搭建本地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#53Name: wordpress.mu
Address: 127.0.0.1
> whatever.wordpress.mu
Server: 127.0.0.1
Address: 127.0.0.1#53Name: whatever.wordpress.mu
Address: 127.0.0.1
>