bind9的初步使用(2)

本文首發於我的博客:bind9的初步使用(2)

設置局域網訪問

比如我的windows 10的ip地址是192.168.1.230。那麼我們可以添加如下內容到/etc/bind/named.conf.options文件中。

    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。

然後在windows 10 上設置DNS爲192.168.1.231114.114.114.114

這樣我們打開cmd,查看域名是否獲取到了正確的ip。

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吧。所以這裏有個簡單的辦法。直接將上面的配置修改如下:

$ 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再次重啓。

首先安裝一個nginx。具體的安裝教程可查看我的另外一篇文章APT安裝NGINX

安裝之後,如果訪問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

最後重啓一下,那麼泛域名設置就成功了。

不早了,要去睡覺了。

晚安。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章