DNS

How can we help?

Навигация
[root@r1 ~]# yum install bind-utils -y      # ставим DNS утилиты
[root@r1 ~]# dig yandex.ru +trace @8.8.8.8  # трасировка DNS от рутовых до тех которые отвечают за конкретный хост
[root@r1 ~]# yum install bind -y 
[root@r1 ~]# vi /etc/named.conf
# добавим в файл вложенную инструкцию
include "/etc/named.conf.local";
[root@r1 ~]# vi /etc/named.conf.local
zone "example.com" {
        type master;
        file "/etc/named/zones/db.example.com"; #файл конфига зоны
};
zone "168.192.in-addr.arpa" {
        type master;
        file "/etc/named/zones/db.168.192"; #файл конфига обратной зоны для
};
[root@r1 ~]# mkdir /etc/named/zones/

[root@r1 ~]# vi /etc/named/zones/db.example.com
$TTL 604800
@ IN SOA ns1.example.com. admin.example.com. (
        20210806 ; Serial
        604800 ; Refresh
        86400 ; Retry
        2419200 ; Expire
        604800 ) ; Negative Cache TTL

 IN NS ns1.example.com. # пробел перед IN обязателен

; name servers - A records
ns1.example.com. IN A 192.168.1.100
abc.example.com. IN A 192.168.1.101
img.example.com. IN A 192.168.1.44
static.example.com IN A 192.168.1.50

[root@r1 ~]# vi /etc/named/zones/db.168.192
$TTL 604800
@ IN SOA example.com. admin.example.com. (
        20210806 ; Serial
        604800 ; Refresh
        86400 ; Retry
        2419200 ; Expire
        604800 ) ; Negative Cache TTL

 IN NS ns1.example.com. # пробел перед IN обязателен

100.1 IN PTR ns1.example.com.
101.1 IN PTR abc.example.com.
44.1 IN PTR img.example.com.
50.1 IN PTR static.example.com.

[root@r1 ~]# named-checkconf /etc/named.conf # проверяем конфиг на наличие ошибок

[root@r1 ~]# named-checkzone example.com /etc/named/zones/db.example.com
zone example.com/IN: loaded serial 20210806
OK
[root@r1 ~]# named-checkzone 168.192.in-addr.arpa /etc/named/zones/db.168.192
zone 168.192.in-addr.arpa/IN: loaded serial 20210806
OK

[root@r1 ~]# systemctl restart named

[root@r1 ~]# dig abc.example.com

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.9 <<>> abc.example.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 30143
;; flags: qr rd ra ad; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;abc.example.com.               IN      A

;; AUTHORITY SECTION:
example.com.            2326    IN      SOA     ns.icann.org. noc.dns.icann.org. 2022040462 7200 3600 1209600 3600

;; Query time: 19 msec
;; SERVER: 77.88.8.7#53(77.88.8.7)
;; WHEN: Ср июл 06 16:44:55 MSK 2022
;; MSG SIZE  rcvd: 100

[root@r1 ~]# dig abc.example.com @127.0.0.1

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.9 <<>> abc.example.com @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37611
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;abc.example.com.               IN      A

;; ANSWER SECTION:
abc.example.com.        604800  IN      A       192.168.1.101

;; AUTHORITY SECTION:
example.com.            604800  IN      NS      ns1.example.com.

;; ADDITIONAL SECTION:
ns1.example.com.        604800  IN      A       192.168.1.100

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Ср июл 06 16:45:15 MSK 2022
;; MSG SIZE  rcvd: 94

# в конфиге мы не ставили точку для домена static.example.com, результат:

[root@r1 ~]# dig static.example.com @127.0.0.1

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.9 <<>> static.example.com @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NXDOMAIN, id: 63823
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 0, AUTHORITY: 1, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;static.example.com.            IN      A

;; AUTHORITY SECTION:
example.com.            604800  IN      SOA     ns1.example.com. admin.example.com. 20210806 604800 86400 2419200 604800

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Ср июл 06 16:48:14 MSK 2022
;; MSG SIZE  rcvd: 93

[root@r1 ~]# dig static.example.com.example.com @127.0.0.1

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.9 <<>> static.example.com.example.com @127.0.0.1
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 18393
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 2

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;static.example.com.example.com.        IN      A

;; ANSWER SECTION:
static.example.com.example.com. 604800 IN A     192.168.1.50

;; AUTHORITY SECTION:
example.com.            604800  IN      NS      ns1.example.com.

;; ADDITIONAL SECTION:
ns1.example.com.        604800  IN      A       192.168.1.100

;; Query time: 0 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Ср июл 06 16:49:58 MSK 2022
;; MSG SIZE  rcvd: 109