linux dns搭建

搭建 Linux 系统的 DNS 服务,通常可以使用以下几种常见的 DNS 服务:

一、常用 DNS 服务

1. Bind9(Berkeley Internet Name Domain)

这是最常用的 DNS 服务,支持 DNS 递归查询、权威解析、转发等。

2. NIS(Network Information Service)

虽然不是 DNS 服务,但可以用于 DNS 的配置管理,适合小型环境。

3. PowerDNS

一个轻量级、高性能的 DNS 服务,支持多种协议(如 BIND、NIS、LDAP 等)。

4. Unbound

一个开源、高性能的 DNS 服务器,支持缓存、转发、安全验证等。

二、搭建 Bind9(Berkeley Internet Name Domain)DNS 服务

1. 安装 Bind9

sudo apt update
sudo apt install bind9 dnsutils -y

2. 配置 Bind9

2.1 配置主配置文件 /etc/bind/named.conf
sudo nano /etc/bind/named.conf

添加以下内容(根据你的需求调整):

options {
    directory  + #引号 + /var/cache/bind + #引号 + ;
    listen-on { 127.0.0.1; 0.0.0.0; };
    listen-on-v6 { ::1; };
    allow-query { any; };
    recursion no;
    forwarders { 8.8.8.8; 8.8.4.4; };
    dnssec-validation no;
};
2.2 配置区域文件(如 example.com
sudo nano /etc/bind/zones/example.com.zone

内容如下:

$TTL 1D
example.com. IN SOA ns1.example.com. admin.example.com. (
    2023101001  ; serial
    10800       ; refresh
    518400      ; retry
    86400       ; expire
    300        ; minimum
)
example.com. IN NS ns1.example.com.
example.com. IN A 192.168.1.10
www.example.com. IN A 192.168.1.11
2.3 启动 Bind9 服务
sudo systemctl unmask bind9
sudo systemctl start bind9
sudo systemctl enable bind9
2.4 检查服务状态
sudo systemctl status bind9

三、使用 Unbound(高性能 DNS 服务器)

1. 安装 Unbound

sudo apt update
sudo apt install unbound -y

2. 配置 Unbound

sudo nano /etc/unbound/unbound.conf

添加以下内容(根据需求调整):

server {
    listen-on-v6 { ::1; };
    listen-on { 127.0.0.1; };
    directory /var/cache/unbound;
    recursion-no;
    forward-lookup-options no;
    forwarders {
        8.8.8.8
        8.8.4.4
    }
    allow-query { 192.168.1.0/24; }
}

3. 启动 Unbound 服务

sudo systemctl start unbound
sudo systemctl enable unbound

四、使用 PowerDNS(推荐)

1. 安装 PowerDNS

sudo apt install pdns-server -y

2. 配置 PowerDNS

sudo nano /etc/powerdns/pdns.conf

添加以下内容:

pdnsd_options = -c /etc/powerdns/pdns.conf

3. 配置区域文件(如 example.com

sudo nano /etc/powerdns/db.example.com

内容如下:

$TTL 1D
example.com. IN SOA ns1.example.com. admin.example.com. (
    2023101001  ; serial
    10800       ; refresh
    518400      ; retry
    86400       ; expire
    300        ; minimum
)
example.com. IN NS ns1.example.com.
example.com. IN A 192.168.1.10
www.example.com. IN A 192.168.1.11

4. 启动 PowerDNS 服务

sudo systemctl start pdns-server
sudo systemctl enable pdns-server

五、常用 DNS 查询命令

dig @8.8.8.8 example.com
nslookup example.com
host example.com

六、总结

服务 优点 缺点 Bind9 大型项目首选,功能强大 配置复杂 Unbound 高性能、轻量级 配置较复杂 PowerDNS 高性能、支持多种协议 配置较复杂

如需进一步配置 DNS 转发、安全、缓存等,请告诉我具体需求,我可以提供更详细的配置方案。

文章转自:[《艾尔登法环:黑夜君临》单人通关经验分享 ] (https://www.52mwyd.com/news/11841.html)

作者:游戏攻略,转载请注明原文链接:https://www.52mwyd.com/

posted @ 2025-11-19 13:31  火麒麟888  阅读(0)  评论(0)    收藏  举报