トップページ > インフォメーション

自宅サーバ構築MY HOME SERVER

DNS(内向き名前解決)(Bind) クライアント側設定

- DNS(内向き名前解決)(Bind) -

グローバルIPアドレスが固定でないことを前提に外向き名前解決は設定しません。DDNSに登録して、IP更新が常にされていれば外部ドメイン からの名前解決はDDNSサービスが提供しています。
ローカルのクライアントPCがドメイン名でサーバにアクセスできるように内向き名前解決の設定します。bindを インストールして、設定する必要があります。

まずはBindのインストールから始めます。
    
root@hoge123:~# aptitude -y install bind9 bind9utils
root@hoge123:~# aptitude -y install bind9-host


named.conf.optionsに変更を加え、保存します。192.168.0.0の部分は、自分の環境に合わせます。 (ルータが192.168.1.1 なら192.168.1.0、ルータが10.0.0.1なら10.0.0.0となります。)
    
root@hoge123:~# vi /etc/bind/named.conf.options

options {
        directory "/etc/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;

        auth-nxdomain no;    # conform to RFC1035
        // listen-on-v6 { any; };
        allow-query { localhost; 192.168.0.0/24; };
        allow-transfer { localhost; 192.168.0.0/24; };
        allow-recursion { localhost; 192.168.0.0/24; };

};


named.conf.localに変更を加え、保存します。
    
root@hoge123:~# vi /etc/bind/named.conf.local

//
// Do any local configuration here
//

// Consider adding the 1918 zones here, if they are not used in your
// organization
//include "/etc/bind/zones.rfc1918";

zone "hoge123.dip.jp" {
   type master;
   file "/etc/bind/hoge123.dip.jp.lan";
};

zone "0.168.192.in-addr.arpa" {
   type master;
   file "/etc/bind/0.168.192.db";
};


hoge123.dip.jp.lanを新規作成をします。192.168.0.10はサーバのIPアドレスです。
    
root@hoge123:~# vi /etc/bind/hoge123.dip.jp.lan

$TTL 86400
@  IN     SOA    hoge123.dip.jp. root.hoge.dip.jp. (
          2010071901    ;Serial
          3600          ;Refresh
          1800          ;Retry
          604800        ;Expire
          86400         ;Minimum TTL
)
          IN    NS      hoge123.dip.jp.
          IN    A       192.168.0.10
          IN    MX 10   hoge123.dip.jp.

hoge123   IN    A       192.168.0.10


0.168.192.dbの新規作成をします。(ルータが192.168.1.1 なら1.168.192.db、ルータが10.0.0.1 なら0.0.10.dbとなります。) 10 IN PTR hoge123.dip.jpの10はサーバのローカルIPアドレス192.168.0.10 の略です。
    
root@hoge123:~# vi /etc/bind/0.168.192.db

$TTL 86400
@  IN   SOA  hoge123.dip.jp. root.hoge123.dip.jp. (
        2010071901      ;Serial
        3600            ;Refresh
        1800            ;Retry
        604800          ;Expire
        86400           ;Minimum TTL
)
  IN  NS   hoge123.dip.jp.

  IN  PTR  hoge123.dip.jp.
  IN  A    255.255.255.0

10 IN  PTR  hoge123.dip.jp.


resolv.confを編集・保存します。
root@hoge123:~# vi /etc/resolv.conf

nameserver 192.168.0.10 ← この記述だけに変更・保存します。

変更・設定が終わったのでBindを開始します。
root@hoge123:~# service bind9 restart

root@hoge123:~# sysv-rc-conf bind9 on ← サーバ再起動時も、Bindが自動起動するようにします。
root@hoge123:~# sysv-rc-conf -list bind9
bind9        0:off      1:off   2:on    3:on    4:on    5:on    6:off
↑ 2〜5までon になっていれば正常です。

ネットワークのDNS設定を変更します。ルータのアドレスから、サーバーのアドレス書き換えます。この設定をしないと サーバが再起動・シャットダウンしたとき、クライアントパソコンからサーバにドメイン名でアクセスできなくなります。
          
root@hoge123:~# vi /etc/network/interfaces

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).

# The loopback network interface
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
# This is an autoconfigured IPv6 interface
#iface eth0 inet6 auto

address 192.168.0.10
network 192.168.0.0
netmask 255.255.255.0
broadcast 192.168.0.255
gateway 192.168.0.1
dns-nameservers 192.168.0.10

Bindが正常動作するかサーバ側でテストします。host コマンドで問い合わせを行い、下図の 用に返答があれば、正常動作しています。
    
root@hoge123:~# host localhost>
localhost has address 127.0.0.1
localhost has IPv6 address ::1
root@hoge123:~# host 192.168.0.10
10.0.168.192.in-addr.arpa domain name pointer hoge123.dip.jp.
root@hoge123:~# host hoge123.dip.jp
hoge123.dip.jp has address 192.168.0.10
hoge123.dip.jp mail is handled by 10 hoge123.dip.jp.




- クライアント側設定 -

クライアントPC側からも名前解決できているか、確認します。ローカルエリア接続のプロパティを 開きます。「インターネットプロトコル」を選択して、「プロパティ」をクリックします。

1.jpg(47293 byte)


「IPアドレスを自動取得する」を選択します。(ルータのDHCP機能が有効になっている必要があります) 「優先DNSサーバ」にサーバのIPアドレスを入れて「OK」を押します。

2.jpg(43961 byte)


「ファイル名を指定して実行」をクリックします。

1.jpg(45388 byte)


「cmd」と入力して「OK」ボタンをクリックします。

3.jpg(16917 byte)


コマンドプロンプトの画面が出たらnslookup コマンドを実行して名前解決できているか確認します。 下図のように表示されれば、クライアントPCから名前解決できています。
        
Microsoft Windows XP [Version 5.1.2600]
(C) Copyright 1985-2001 Microsoft Corp.

C:\Documents and Settings\hogehoge>nslookup
Default Server: hoge123.dip.jp
Address: 192.168.0.10

>hoge123.dip.jp
Server:  hoge123.dip.jp
Address:  192.168.0.10

Name:  hoge123.dip.jp
Address:  192.168.0.10

>192.168.0.10
Server:  hoge123.dip.jp
Address:  192.168.0.10

Name:  hoge123.dip.jp
Address:  192.168.0.10

>exit

C:\Documents and Settings\hogehoge>>exit


これでクライアントPCからサーバのローカルIPアドレスでなく、ドメイン名でアクセスできます。 例えば、Tera Termのログイン時も、「ホスト」にhoge123.dip.jpを入力します。

自宅サーバ構築(Ubuntu12.04TLS)に戻る


Copyright(C) PCDEMAGIC All Rights Reserved.