dns 全称是 domain name system,大意是域名解析系统,它的职责是把域名翻译成一个一个可以识别的 ip 供不同的计算机设备连接。
linux 中有三个文件是关于 dns 解析的:
/etc/hosts
的存在是早期网络并不是特别发达,仅仅在 hosts 中保存主机名和 ip 地址的对应关系即可满足需要,随着网络的发展逐渐出现分布式 dns 服务,但是 /etc/hosts
形式保留下来了。
/etc/resolv.conf
是配置dns 域名和 ip 地址的,网上有很多资料可以参考一下。
how the domain name system (dns) works这篇大致解释了域名被解析的过程,基本可以分为:
yum install bind
vim /etc/named.conf
options { listen-on port 53 { any; }; //开启监听端口53,接受任意ip连接 listen-on-v6 port 53 { ::1; }; //支持ip v6 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"; allow-query { 0.0.0.0/0; }; //允许任意ip查询 recursion yes; dnssec-enable yes; dnssec-validation yes; dnssec-lookaside auto; /* path to isc dlv key */ bindkeys-file "/etc/named.iscdlv.key"; managed-keys-directory "/var/named/dynamic"; }; logging { channel default_debug { file "data/named.run"; severity dynamic; }; }; zone "." in { type hint; file "named.ca"; }; include "/etc/named.rfc1912.zones"; //主要配置文件 include "/etc/named.root.key";
vim /etc/ named.rfc1912.zones
zone "localhost.localdomain" in { type master; file "named.localhost"; allow-update { none; }; }; zone "localhost" in { type master; file "named.localhost"; allow-update { none; }; }; zone "1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa" in { type master; file "named.loopback"; allow-update { none; }; }; zone "1.0.0.127.in-addr.arpa" in { type master; file "named.loopback"; allow-update { none; }; }; zone "0.in-addr.arpa" in { type master; file "named.empty"; allow-update { none; }; }; //duiyi.com的正向区域 zone "duiyi.com" in { type master; file "duiyi.com.zone"; allow-update { none; }; };
vim /var/named/duiyi.com.zone
$ttl 1d @ in soa duiyi.com. rname.invalid. ( 0 ; serial 1d ; refresh 1h ; retry 1w ; expire 3h ) ; minimum ns @ a 127.0.0.1 aaaa ::1 www in a 192.168.81.1 mail in a 192.168.81.2 ftp in a 192.168.81.3
systemctl start named
systemctl enable named
## 客户端
操作系统:windows和linux都可以
ip地址:能够ping通dns服务器的ip(192.168.81.133)都可以,
作用:测试dns服务器是否正常工作。
如图所示则表示dns正向解析成功
yum install bind-utils
vim /etc/resolv.conf
nameserver 192.168.81.133 nameserver 114.114.114.114 nameserver 8.8.8.8
nslookup
如对本文有疑问, 点击进行留言回复!!
linux下文本编辑器vim的使用方法(复制、粘贴、替换、行号、撤销、多文件操作)
网友评论