本文首发于个人博客:bind9的初步使用(2)nginx
好比个人windows 10的ip地址是192.168.1.230。那么咱们能够添加以下内容到/etc/bind/named.conf.options
文件中。windows
listen-on {
192.168.1.230;
192.168.1.231;
};
复制代码
填写完成后打开/etc/bind/named.conf.options
内容以下:浏览器
$ cat /etc/bind/named.conf.options
options {
directory "/var/cache/bind";
// If there is a firewall between you and nameservers you want
// to talk to, you may need to fix the firewall to allow multiple
// ports to talk. See http://www.kb.cert.org/vuls/id/800113
// If your ISP provided one or more IP addresses for stable
// nameservers, you probably want to use them as forwarders.
// Uncomment the following block, and insert the addresses replacing
// the all-0's placeholder. // forwarders { // 114.114.114.114; // }; //======================================================================== // If BIND logs error messages about the root key being expired, // you will need to update your keys. See https://www.isc.org/bind-keys //======================================================================== dnssec-validation auto; listen-on-v6 { any; }; listen-on { 192.168.1.230; 192.168.1.231; }; }; 复制代码
重启bind9。bash
而后在windows 10 上设置DNS为192.168.1.231
和114.114.114.114
。服务器
这样咱们打开cmd,查看域名是否获取到了正确的ip。iphone
PS C:\Users\baogu> ping www.baoguoxiao.pro
正在 Ping www.baoguoxiao.pro [192.168.1.231] 具备 32 字节的数据:
来自 192.168.1.231 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.1.231 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.1.231 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.1.231 的回复: 字节=32 时间=1ms TTL=64
192.168.1.231 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 0ms,最长 = 1ms,平均 = 0ms
复制代码
可是若是咱们这边手机要连怎么办。不能每次都加ip吧。因此这里有个简单的办法。直接将上面的配置修改以下:ide
$ cat /etc/bind/named.conf.options
options {
directory "/var/cache/bind";
// If there is a firewall between you and nameservers you want
// to talk to, you may need to fix the firewall to allow multiple
// ports to talk. See http://www.kb.cert.org/vuls/id/800113
// If your ISP provided one or more IP addresses for stable
// nameservers, you probably want to use them as forwarders.
// Uncomment the following block, and insert the addresses replacing
// the all-0's placeholder. // forwarders { // 0.0.0.0; // }; //======================================================================== // If BIND logs error messages about the root key being expired, // you will need to update your keys. See https://www.isc.org/bind-keys //======================================================================== dnssec-validation auto; listen-on-v6 { any; }; listen-on { any; }; }; 复制代码
这样直接将ip列表修改成any。就能够接收全部的ip了。测试
这个时候咱们将bind9再次重启。ui
首先安装一个nginx。具体的安装教程可查看个人另一篇文章APT安装NGINXspa
安装以后,若是访问192.168.1.231,就能看到默认的nginx页面了。
每一个手机是设置是不一样的。我这里是iphone,版本是12.1.1。
进入设置->无线局域网->在已链接的WIFI右边点击带圈的感叹号->配置DNS->选择手动。
最后点击添加服务器,输入咱们虚拟机的地址:192.168.1.231。
这个时候咱们在手机的浏览器里面输入咱们以前设置的域名www.baoguoxiao.pro。就能看到咱们经典的nginx主页了。
这样咱们就可使用手机访问咱们的电脑页面了。在调试某些状况的时候,是否是感受会很是方便呢。
在开发的时候,可能会出现使用多个域名的状况,可是若是每次添加域名都要设置bind9,还要重启,很是麻烦,那么有没有简单的办法呢?有,就是使用泛域名设置。
废话很少说,请看以下配置:
$ cat /etc/bind/zones/baoguoxiao.pro.db
; BIND data file for baoguoxiao.pro
;
$TTL 14400
@ IN SOA ns1.baoguoxiao.pro. host.baoguoxiao.pro. (
201006601 ; Serial
7200 ; Refresh
120 ; Retry
2419200 ; Expire
604800) ; Default TTL
;
baoguoxiao.pro. IN NS ns1.baoguoxiao.pro.
;baoguoxiao.pro. IN A 192.168.1.231
ns1 IN A 192.168.1.231
www IN A 192.168.1.231
复制代码
这个是咱们以前上一篇文章对其的设置。那么若是要设置泛域名,只须要把最后一行的www
更改成*
就能够了。
那么切换后的配置以下:
$ cat /etc/bind/zones/baoguoxiao.pro.db
; BIND data file for baoguoxiao.pro
;
$TTL 14400
@ IN SOA ns1.baoguoxiao.pro. host.baoguoxiao.pro. (
201006601 ; Serial
7200 ; Refresh
120 ; Retry
2419200 ; Expire
604800) ; Default TTL
;
baoguoxiao.pro. IN NS ns1.baoguoxiao.pro.
;baoguoxiao.pro. IN A 192.168.1.231
ns1 IN A 192.168.1.231
* IN A 192.168.1.231
复制代码
最后重启一下,那么泛域名设置就成功了。
不早了,要去睡觉了。
晚安。