Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Linux Domain name Service DNS configuration method

2025-02-27 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

什么是 DNS

DNS 全称是 Domain Name System,大意是域名解析系统,它的职责是把域名翻译成一个一个可以识别的 IP 供不同的计算机设备连接。

linux 有关 DNS 解析的配置和文件

linux 中有三个文件是关于 dns 解析的:

/etc/hosts 记录 hostname 对应的ip地址/etc/resolv.conf 设置DNS服务器的ip地址/etc/host.conf 指定域名解析的顺序(是从本地的hosts文件解析还是从DNS解析)/etc/hosts 的存在是早期网络并不是特别发达,仅仅在 hosts 中保存主机名和 ip 地址的对应关系即可满足需要,随着网络的发展逐渐出现分布式 DNS 服务,但是 /etc/hosts 形式保留下来了。

/etc/resolv.conf 是配置DNS 域名和 ip 地址的,网上有很多资料可以参考一下。

一个域名是如何被解析的

How the Domain Name System (DNS) Works这篇大致解释了域名被解析的过程,基本可以分为:

向根域名服务请求顶级域名所在所在域名服务向顶级域名服务请求二级域名服务向二级域名服务请求具体的 ip 地址

简易DNS配置案例(基于CentOs7)

服务器端

1.安装bind

yum install bind

2.修改/etc/named.conf配置文件

vim /etc/named.confoptions { 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";

3.修改/etc/named.rfc1912.zones文件,添加duiyi.com的正向区域

vim /etc/ named.rfc1912.zoneszone "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; };};

4.创建正向区域资源文件

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 ::1www IN A 192.168.81.1mail IN A 192.168.81.2ftp IN A 192.168.81.3

5.启动named服务

systemctl start named

6.开机自启动

systemctl enable named

## 客户端

操作系统:windows和linux都可以

IP地址:能够ping通DNS服务器的IP(192.168.81.133)都可以,

作用:测试DNS服务器是否正常工作。

1.修改DNS:

2.ping 服务端ip(192.168.81.133),测试能否访问服务器

3.使用nslookup命令测试三个DNS解析能否成功

As shown in the figure, it means that DNS forward resolution is successful

Linux as a client test:

1. Install the bind-utils package so you can use nslookup, dig, and host tools

yum install bind-utils

2. Modify DNS configuration Use our DNS server

vim /etc/resolv.confnameserver 192.168.81.133nameserver 114.114.114.114nameserver 8.8.8.8

3. Forward parsing test, using nslookup command (consistent with windows test)

nslookup

summary

The above is the Linux DNS configuration method introduced by Xiaobian to you. I hope it will help you. If you have any questions, please leave a message to me. Xiaobian will reply to you in time. Thank you very much for your support!

If you think this article is helpful to you, welcome to reprint, please indicate the source, thank you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report