1.安装pdnsd服务

apt-get install pdnsd

2.编辑或替换配置文件

vim /etc/pdnsd.conf

配置文件

// Read the pdnsd.conf(5) manpage for an explanation of the options.

/* Note: this file is overriden by automatic config files when
   /etc/default/pdnsd AUTO_MODE is set and that
   /usr/share/pdnsd/pdnsd-$AUTO_MODE.conf exists
 */

global {
    perm_cache=4096;
    cache_dir="/var/cache/pdnsd";
    run_as="pdnsd";
    server_ip = eth0;  // Use eth0 here if you want to allow other
                // machines on your network to query pdnsd.
    server_port = 5050;
    status_ctl = on;
      paranoid=on;
//    query_method=tcp_udp;    // pdnsd must be compiled with tcp
                // query support for this to work.
    min_ttl=1d;       // Retain cached entries at least 15 minutes.
    max_ttl=1w;       // One week.
    neg_ttl=120s;
    timeout=5;        // Global timeout option (10 seconds).

        // Don't enable if you don't recurse yourself, can lead to problems
        // delegation_only="com","net";
}

server {
    label = "mydns";
    ip =     8.8.8.8
    ,    8.8.4.4
    ;
    timeout = 3;
    uptest = none;
    purge_cache = off;
    edns_query = on;
    exclude = .localdomain;
}

/* with status_ctl=on and resolvconf installed, this will work out from the box
   this is the recommended setup for mobile machines */
/*
server {
    label="resolvconf";
}
*/

/*
// This section is meant for resolving from root servers.
server {
    label = "root-servers";
    root_server=on;
    ip =     198.41.0.4
    ,    192.228.79.201
    ,    192.33.4.12
    ,    128.8.10.90
    ,    192.203.230.10
    ,    192.5.5.241
    ,    192.112.36.4
    ,    128.63.2.53
//    ,    192.36.148.17
//    ,    192.58.128.30
//    ,    193.0.14.129
//    ,    198.32.64.12
//    ,    202.12.27.33
    ;
    timeout = 5;
    uptest = query;
    interval = 30m;      // Test every half hour.
    ping_timeout = 300;  // 30 seconds.
    purge_cache = off;
    exclude = .localdomain;
    policy = included;
    preset = off;
}
*/

source {
    owner=localhost;
//    serve_aliases=on;
    file="/etc/hosts";
}

rr {
    name=localhost;
    reverse=on;
    a=127.0.0.1;
    owner=localhost;
    soa=localhost,root.localhost,42,86400,900,86400,86400;
}

/*
neg {
    name=doubleclick.net;
    types=domain;   // This will also block xxx.doubleclick.net, etc.
}
*/

/*
neg {
    name=bad.server.com;   // Badly behaved server you don't want to connect to.
    types=A,AAAA;
}
*/

/* vim:set ft=c: */
vim /etc/default/pdnsd

START_DAEMON=no → START_DAEMON=yes

3.重启服务

service pdnsd restart

4.测试,执行如下命令

dig @13.75.77.214 -p 5050 www.youtube.com

得到如下结果,OK

[email protected]:~# dig @13.75.77.214 -p 5050 www.youtube.com

; <<>> DiG 9.10.3-P4-Ubuntu <<>> @13.75.77.214 -p 5050 www.youtube.com
; (1 server found)
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 27717
;; flags: qr rd ra; QUERY: 1, ANSWER: 17, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1024
;; QUESTION SECTION:
;www.youtube.com.               IN      A

;; ANSWER SECTION:
www.youtube.com.        83100   IN      CNAME   youtube-ui.l.google.com.
youtube-ui.l.google.com. 83100  IN      A       172.217.22.14
youtube-ui.l.google.com. 83100  IN      A       172.217.18.174
youtube-ui.l.google.com. 83100  IN      A       216.58.206.14
youtube-ui.l.google.com. 83100  IN      A       216.58.207.46
youtube-ui.l.google.com. 83100  IN      A       216.58.207.78
youtube-ui.l.google.com. 83100  IN      A       216.58.214.46
youtube-ui.l.google.com. 83100  IN      A       216.58.214.78
youtube-ui.l.google.com. 83100  IN      A       172.217.16.174
youtube-ui.l.google.com. 83100  IN      A       216.58.208.46
youtube-ui.l.google.com. 83100  IN      A       172.217.22.46
youtube-ui.l.google.com. 83100  IN      A       216.58.214.110
youtube-ui.l.google.com. 83100  IN      A       172.217.22.110
youtube-ui.l.google.com. 83100  IN      A       172.217.23.174
youtube-ui.l.google.com. 83100  IN      A       216.58.205.238
youtube-ui.l.google.com. 83100  IN      A       172.217.21.206
youtube-ui.l.google.com. 83100  IN      A       172.217.21.238

;; Query time: 74 msec
;; SERVER: 13.75.77.214#5050(13.75.77.214)
;; WHEN: Thu Nov 15 21:05:02 DST 2018
;; MSG SIZE  rcvd: 334