Ubuntu 19.04搭建私有DNS
- 安装BIND
# cat /etc/issue
Ubuntu 19.04 \n \l
# add-apt-repository -y ppa:isc/bind
# apt-get update
# apt-get install -y bind9
- 配置BIND服务器, 运行客户端进行recursion查询和转发
# vi /etc/bind/named.conf.options
> listen-on { 172.16.13.8; };
> recursion yes;
> allow-recursion { any; };
> forwarders {
> 100.100.2.138;
> 8.8.8.8;
> };
# systemctl restart named
- 添加dns数据
# cd /var/cache/bind/
# cat << EOF > db.example.com
>TTL 600
>\$ORIGIN example.com.
>@ IN SOA ns1.example.com root.example.com (
> 20190715 ;Serial
> 1h ;Refresh
> 5m ;Retry
> 1w ;Expire
> 1h ;Minimum
>)
>@ IN A 172.16.13.81
>@ IN NS ns1
>ns1 IN A 172.16.13.81
>git IN A 172.16.13.81
>EOF
# echo db.example.com
$TTL 600
$ORIGIN example.com.
@ IN SOA ns1.example.com root.example.com (
20190715 ;Serial
1h ;Refresh
5m ;Retry
1w ;Expire
1h ;Minimum
)
@ IN A 172.16.13.81
@ IN NS ns1
ns1 IN A 172.16.13.81
git IN A 172.16.13.81
# named-checkzone example.com db.example.com
# vi /etc/bind/named.conf.local
>zone "example.com" {
> type master;
> file "db.example.com";
> forwarders {};
};
# systemctl restart named
- 测试, DNS服务所在的ip为172.16.13.8
# dig @172.16.13.8 git.example.com
# dig @172.16.13.8 www.bing.com
扩展知识
1. linux查看当前所有的服务命令:service --status-all
2. dns的两种查询模式iterative、recursive
参考资料
https://www.isc.org/bind/ https://downloads.isc.org/isc/bind9/9.14.3/doc/arm/Bv9ARM.pdf https://launchpad.net/~isc/+archive/ubuntu/bind https://docs.microsoft.com/zh-cn/windows-server/identity/ad-ds/plan/reviewing-dns-concepts https://linuxhint.com/install_bind9_ubuntu/ https://www.slashroot.in/difference-between-iterative-and-recursive-dns-query https://www.digitalocean.com/community/tutorials/an-introduction-to-dns-terminology-components-and-concepts