本文首發於個人博客: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
複製代碼
最後重啓一下,那麼泛域名設置就成功了。
不早了,要去睡覺了。
晚安。