加入收藏 | 设为首页 | 会员中心 | 我要投稿 辽源站长网 (https://www.0437zz.com/)- 云专线、云连接、智能数据、边缘计算、数据安全!
当前位置: 首页 > 站长资讯 > 外闻 > 正文

使用 CoreDNS 来应对 DNS 污染

发布时间:2019-04-02 15:28:47 所属栏目:外闻 来源:yangcs
导读:CoreDNS 是新晋的 CNCF 孵化项目,前几天已经从 CNCF 正式毕业,并正式成为 Kubernetes 的 DNS 服务器。CoreDNS 的目标是成为 cloud-native 环境下的 DNS 服务器和服务发现解决方案,即: Our goal is to make CoreDNS the cloud-native DNS server and se

讲一下我自己的理解:

  1. 配置文件类似于 nginx 配置文件的格式;
  2. 最外面一级的大括号,对应『服务』的概念。多个服务可以共用一个端口;
  3. 往里面一级的大括号,对应 plugins 的概念,每一个大括号都是一个 plugin。这里可以看出,plugins 是 CoreDNS 的一等公民;
  4. 服务之间顺序有无关联没有感觉,但 plugins 之间是严重顺序相关的。某些 plugin 必须用 fallthrough 关键字流向下一个 plugin;
  5. plugin 内部的配置选项是顺序无关的;
  6. 从 plugins 页面的介绍看,CoreDNS 的功能还是很强的,既能轻松从 bind 迁移,还能兼容 old-style dns server 的运维习惯;
  7. 从 CoreDNS 的性能指标看,适合做大型服务。

当然了,上面的配置文件还可以升级一下,具体我就不解释了:

  1. . { 
  2.   hosts { 
  3.     fallthrough 
  4.   } 
  5.  
  6.   forward . 127.0.0.1:5301 127.0.0.1:5302 { 
  7.     max_fails 3 
  8.     expire 10s 
  9.     health_check 5s 
  10.     policy sequential 
  11.     except www.baidu.com 
  12.   } 
  13.  
  14.   proxy . 117.50.11.11 117.50.22.22 { 
  15.     policy round_robin 
  16.   } 
  17.  
  18.   cache 120 
  19.   reload 6s 
  20.   log . "{local}:{port} - {>id} '{type} {class} {name} {proto} {size} {>do} {>bufsize}' {rcode} {>rflags} {rsize} {duration}" 
  21.   errors 
  22.  
  23. .:5301 { 
  24.   forward . tls://8.8.8.8 tls://8.8.4.4 { 
  25.     tls_servername dns.google 
  26.     force_tcp 
  27.     max_fails 3 
  28.     expire 10s 
  29.     health_check 5s 
  30.     policy sequential 
  31.   } 
  32.  
  33. .:5302 { 
  34.   forward . tls://1.1.1.1 tls://1.0.0.1 { 
  35.     tls_servername 1dot1dot1dot1.cloudflare-dns.com 
  36.     force_tcp 
  37.     max_fails 3 
  38.     expire 10s 
  39.     health_check 5s 
  40.     policy sequential 
  41.   } 

定时更新国内域名列表

编写一个 shell 脚本,用来更新 Corefile 中排除的国内域名列表:

  1. $ brew install gnu-sed 
  2. $ cat <<EOF > /usr/local/bin/update_coredns.sh 
  3. #!/bin/bash 
  4.  
  5. chinadns=$(curl -sL https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf|awk -F "/" '{print $2}') 
  6. touch update_coredns.sed && echo "" > update_coredns.sed 
  7. for i in $chinadns; do echo "/except/ s/$/ $i/" >> update_coredns.sed; done 
  8. gsed -i "s/(except).*/1/" /usr/local/etc/Corefile 
  9. gsed -i -f update_coredns.sed /usr/local/etc/Corefile 
  10. EOF 
  11. $ sudo chmod +x /usr/local/bin/update_coredns.sh 

先执行一遍该脚本,更新 Corefile 的配置:

  1. $ /usr/local/bin/update_coredns.sh 

然后通过 Crontab 制作定时任务,每隔两天下午两点更新域名列表:

  1. $ crontab -l 
  2. 0 14 */2 * * /usr/local/bin/update_coredns.sh 

开机自启

(编辑:辽源站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

推荐文章
    热点阅读