DNS搭建
工作原理
域名解析服务器,域名(FQDN)-->IP地址,存在正向解析和反向解析,基于UDP/TCP 端口:53,
一个ip对应多个域名
一个域名对应多个ip
1,安装
apt -y install bind9 dnsutils
2,配置文件
# vim /etc/bind/named.conf.default-zones
// prime the server with knowledge of the root servers
zone "." { #根域
type hint; #根区域
file "/usr/share/dns/root.hints";
};
zone "mahao.com" { #正向区域
type master; #类型:主区域
file "/etc/bind/db.mahao.com"; #正向解析存放位置
};
zone "11.168.192.in-addr.arpa" { #反向解析
type master; #类型:主区域
file "/etc/bind/db.192"; #反向解析存放位置
};
# cd /etc/bind
# cp db.local db.mahao.com
# cp db.127 db.192
# vim db.mahao.com #正向解析是指根据域名(主机名)查找到对应的IP地址
;
; BIND data file for local loopback interface
;
$TTL 604800
@ IN SOA mahao.com. root.mahao.com. (
2 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
IN NS www.mahao.com.
www A 192.168.11.200
# vim db.192 #反向解析的作用是将用户提交的IP地址解析为对应的域名信息
;
; BIND reverse data file for local loopback interface
;
$TTL 604800
@ IN SOA mahao.com. root.mahao.com. (
1 ; Serial
604800 ; Refresh
86400 ; Retry
2419200 ; Expire
604800 ) ; Negative Cache TTL
;
IN NS www.mahao.com.
200 PTR www.mahao.com. #PTR为指针记录,用于反向解析
正向区域的内容详解q 2819876040
3,重启解析
root@debian:/etc/bind# /etc/init.d/bind9 restart
[ ok ] Restarting bind9 (via systemctl): bind9.service.
root@debian:/etc/bind# nslookup www.mahao.com 192.168.11.68
Server: 192.168.11.68
Address: 192.168.11.68#53
Name: www.mahao.com
Address: 192.168.11.200
Name: www.mahao.com
Address: 192.168.11.200