智能DNS

智能DNS

本文实现了 内网 DNS 解析到内网地址

  1. 安装bind9

    dnf install bind9

  2. 修改配置

    /etc/bind/named.conf
    // This is the primary configuration file for the BIND DNS server named.
    //
    // Please read /usr/share/doc/bind9/README.Debian for information on the
    // structure of BIND configuration files in Debian, *BEFORE* you customize
    // this configuration file.
    //
    // If you are just adding zones, please do that in /etc/bind/named.conf.local
    
    include "/etc/bind/named.conf.options";
    include "/etc/bind/named.conf.local";
    // include "/etc/bind/named.conf.default-zones";
    /etc/bind/named.conf.local
    acl "internal-net" {
        192.168.31.0/24;
    };
    
    view "internal" {
        match-clients { "internal-net"; };
        recursion yes;
        allow-recursion { "internal-net"; };
        zone "devcxl.cn" {
            type master;
            file "/etc/bind/zones/db.devcxl.cn.internal";
        };
        include "/etc/bind/named.conf.default-zones";
    };
    
    view "external" {
        match-clients { any; };
        recursion no;
        include "/etc/bind/named.conf.default-zones";
    };
    /etc/bind/zones/db.devcxl.cn.internal
    $TTL 86400
    @   IN  SOA ns.devcxl.cn. admin.devcxl.cn. (
            2024052001 ; Serial
            3600       ; Refresh
            1800       ; Retry
            604800     ; Expire
            86400 )    ; Minimum
    
        IN  NS  ns.devcxl.cn.
    ns  IN  A   192.168.31.177
    admin IN A  192.168.31.127
    console IN  A 192.168.31.137
    monitor IN A 192.168.31.147
  3. 自启动

    systemctl enable --now bind9.service

  4. 路由器设置DNS为安装bind9的地址

参考资料