使用coredns搭建自定义dns服务器

下载

官方链接:CoreDNS: DNS and Service Discovery

下载地址:https://github.com/coredns/coredns/releases/download/v1.8.6/coredns_1.8.6_darwin_amd64.tgz

步骤

1. 下载后解压coredns二进制文件到/bin目录

2. 在/etc/coredns增加配置文件Corefile,以及myhosts文件

Corefile文件内容为:

# 默认53端口
.:53 {
    root /etc/coredns/

    #log
    health {
      lameduck 5s    
    }

    errors
    # 读取/etc/hosts风格的配置文件,每5S会热加载一次myhosts文件
    hosts myhosts

    # 向上转发的DNS,这里演示的8.8.8.8为谷歌DNS
    forward . 8.8.8.8

    cache 30

    loop

    reload 30s

    loadbalance
}

myhosts文件:(/etc/hosts风格的映射文件)

172.17.20.120 nginx.local.com

运行

coredns -conf=/etc/coredns/Corefile

设置以service方式启动:/usr/lib/systemd/system/coredns.service

[Unit]
Description=coredns
Documentation=https://coredns.io
Wants=network.target
After=network.target

[Service]
ExecStart=/usr/local/bin/coredns -conf=/etc/coredns/Corefile
Restart=always
StartLimitInterval=0
RestartSec=10

[Install]
WantedBy=multi-user.target

重启命令:

service coredns restart

测试

ping nginx.local.com

额外说明

经过jmeter压力测试,coredns吞吐量是bind9(named)的2倍多。

你可能感兴趣的:(linux,coredns,named,bind9,linux,kubernetes)