bind9的初步使用(2)
- 2019 年 12 月 1 日
- 筆記
設置區域網訪問
比如我的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.231
和114.114.114.114
。
這樣我們打開cmd,查看域名是否獲取到了正確的ip。
PS C:Usersbaogu> 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
這個是我們之前bind9的初步使用(1)對其的設置。那麼如果要設置泛域名,只需要把最後一行的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
最後重啟一下,那麼泛域名設置就成功了。