---
# System prepended metadata

title: （三）DNS Server設定

---

# （三）DNS Server設定
## server端
```
$ vim /etc/named.conf
```
```dockerfile=
#執行結果
options {
        listen-on port 53 { any; };
        //listen-on-v6 port 53 { ::1; };
        directory       "/var/named";
        dump-file       "/var/named/data/cache_dump.db";
        statistics-file "/var/named/data/named_stats.txt";
        memstatistics-file "/var/named/data/named_mem_stats.txt";
        secroots-file   "/var/named/data/named.secroots";
        recursing-file  "/var/named/data/named.recursing";
        allow-query     { any; };
        //allow-query-cache {any;};
        allow-transfer { none; };

        recursion yes;

        dnssec-enable yes;
        dnssec-validation yes;

        managed-keys-directory "/var/named/dynamic";

        pid-file "/run/named/named.pid";
        session-keyfile "/run/named/session.key";

        include "/etc/crypto-policies/back-ends/bind.config";
};

logging {
        channel default_debug {
                file "data/named.run";
                severity dynamic;
        };
};

zone "." IN {
        type hint;
        file "named.ca";
};
zone "chuck.im.shu" IN{
        type master;
        file "named.linux.shu";
};
zone "10.24.172.in-addr.arpa" IN{
        type master;
        file "named.192.168.1";
};
include "/etc/named.rfc1912.zones";
include "/etc/named.root.key";
```
```
$ vim /var/named/named.linux.shu
```
```dockerfile=
#執行結果
$TTL    600
@       IN SOA  master.chuck.im.shu. shu.chuck.im.shu. (
                                                2011080401 3H 15M 1W 1D )
@       IN NS   master.chuck.im.shu.
master.chuck.im.shu. IN A       172.24.10.8
@       IN MX 10 chuck.im.shu.

chuck.im.shu.   IN A    172.24.10.8
centos.chuck.im.shu.    IN      CNAME   chuck.im.shu.
ftp.chuck.im.shu.       IN      CNAME   chuck.im.shu.
forum.chuck.im.shu.     IN      CNAME   chuck.im.shu.

kvm8.chuck.im.shu.      IN      A       172.24.10.3
kvm10.chuck.im.shu.     IN      A       172.24.10.5
```
```
$ vim /var/named/named.192.168.1
```
```dockerfile=
#執行結果
$TTL    600
@       IN SOA master.chuck.im.shu. shu.chuck.im.shu. (
                                        2011080401 3H 15M 1W 1D )
@       IN NS master.chuck.im.shu.
@       IN NS kvm8.chuck.im.shu.
@       IN NS kvm10.chuck.im.shu.
8       IN PTR master.chuck.im.shu.

8       IN PTR chuck.im.shu.

3       IN PTR kvm8.chuck.im.shu.
5       IN PTR kvm10.chuck.im.shu.
```
```
$ vim /etc/resolv.conf
```
```dockerfile=
#執行結果
#將原本檔案更改成以下內容

# Generated by NetworkManager
search chuck.im.shu
```
```
$ vim /etc/nsswitch.conf
```
```dockerfile=
#執行結果
#nsswitch.conf檔案有很多找到下面這行確認即可
hosts:      files dns myhostname
```
```
$ vim /etc/hosts
```
```dockerfile=
#執行結果
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.24.10.8	chuck.im.shu master.chuck.im.shu
```
```
$ hostnamectl set-hostname chuck.im.shu
```
```
$ systemctl restart named
$ systemctl enable named
$ reboot
```
測試
```
$ dig chuck.im.shu
```
```dockerfile=
#執行結果
#找到下面這行answer section確認即可
;; ANSWER SECTION:
chuck.im.shu.		600	IN	A	172.24.10.8
```
```
$ dig kvm8.chuck.im.shu
```
```dockerfile=
#執行結果
#找到下面這行answer section確認即可
;; ANSWER SECTION:
kvm8.chuck.im.shu.	600	IN	A	172.24.10.3
```
## client端
```
$ vim /etc/sysconfig/network-scripts/ifcfg-enp0s3
```
```dockerfile=
#執行結果
#直接在檔案中新增下面這行
DNS1=172.24.10.3
```
```
$ vim /etc/hosts
```
```dockerfile=
#執行結果
#直接在檔案中新增下面兩行
172.24.10.3    kvm8.chuck.im.shu
172.24.10.8    chuck.im.shu master.chuck.im.shu   
```
```
$ vim /etc/resolv.conf
```
```dockerfile=
#執行結果
#將原本檔案更改成以下內容

# Generated by NetworkManager
serch chuck.im.shu
nameserver 172.24.10.3
```
```
$ vim /etc/nsswitch.conf
```
```dockerfile=
#執行結果
#nsswitch.conf檔案有很多找到下面這行確認即可
hosts:      files dns myhostname
```
```
$ hostnamectl set-hostname kvm8.chuck.im.shu
$ reboot
```
測試
```
$ ping kvm8.chuck.im.shu
$ ping chuck.im.shu
```
:::success
皆能ping通表示DNS設定完成:clap: 
:::
:::info
kvm10同kvm8設定
把內容有kvm8都改成kvm10即可
IP也改為172.24.10.5就好
:::