menu Chancel's blog
rss_feed
Chancel's blog
有善始者实繁,能克终者盖寡。

自建DNS解析服务器overture

作者:Chancel Yang, 创建:2022-07-26, 字数:2626, 已阅:139, 最后更新:2022-07-26

这篇文章更新于 639 天前,文中部分信息可能失效,请自行甄别无效内容。

在不使用魔法爱国的时候,访问github/nintendo等海外网站,总是特别慢

查阅了相关资料,发现是国内的DNS解析对这些海外域名存在不同程度的污染情况导致的

那么处理方法就比较简单了,可以通过自建一个DNS服务解析服务器来解决这个问题

自建DNS解析服务器有2个明显好处

  • 解决DNS污染,加速github等没有被管控的海外网站访问速度
  • 防止DNS劫持(即访问www.baidu.com被重定向到非百度的服务器去)

注:自建DNS解析服务器并不能解决访问完全受限的网站(SNI阻断)

overture是一款DNS解析器,比起经典老菜ChinaDNS的优点是设置更加丰富,设置也更简单一些

overture仓库:shawn1m/overture - github.com

从仓库的release中下载最新的安装包后解压,并保留默认配置文件用于恢复

Bash
mkdir -p ~/apps/overture && cd ~/apps/overture
wget https://github.com/shawn1m/overture/releases/download/v1.8/overture-linux-amd64.zip
unzip overture-linux-amd64.zip
cp config.yml config.yml.bak

然后编辑配置文件config.yaml,其参考例子如下

YAML
bindAddress: :53
debugHTTPAddress: 127.0.0.1:5555
dohEnabled: false
primaryDNS:
  - name: DNS114
    address: 114.114.114.114:53
    protocol: udp
    socks5Address:
    timeout: 6
    ednsClientSubnet:
      policy: disable
      externalIP:
      noCookie: true
  - name: AliDNS
    address: 223.5.5.5:53
    protocol: udp
    socks5Address:
    timeout: 6
    ednsClientSubnet:
      policy: disable
      externalIP:
      noCookie: true
onlyPrimaryDNS: false
alternativeDNS:
  - name: CloudFlareDNS
    address: 8.8.4.4:53
    protocol: udp
    # 查询时是否使用socks5代理(注意protocol,部分ss可能不支持转发udp请求,可牺牲一部分速度改protocol成tcp)
    socks5Address:
    timeout: 6
    ednsClientSubnet:
      policy: disable
      externalIP:
      noCookie: true
  - name: GoogleDNS
    address: 8.8.4.4:53
    protocol: udp
    # 查询时是否使用socks5代理(注意protocol,部分ss可能不支持转发udp请求,可牺牲一部分速度改protocol成tcp)
    socks5Address:
    timeout: 6
    ednsClientSubnet:
      policy: disable
      externalIP:
      noCookie: true
ipv6UseAlternativeDNS: false
alternativeDNSConcurrent: false
whenPrimaryDNSAnswerNoneUse: primaryDNS
ipNetworkFile: # 优先级匹配,如IP在primary文件中则直接返回primaryDNS结果,反之亦然,这里可以引入国内的IP段(如chnrouter列表),alternative默认即可
  primary: ./ip_network_china_ip
  alternative: ./ip_network_alternative_sample
domainFile: # 优先级匹配,如域名在primary文件中则直接返回primaryDNS结果,反之亦然,这里在alternative中引入gfwlist列表,primary默认即可
  primary: ./domain_primary_sample
  alternative: ./domain_alternative_gfwlist
  matcher: full-map
hostsFile:
  hostsFile: /etc/hosts
  finder: full-map
minimumTTL: 0
domainTTLFile: ./domain_ttl_sample
cacheSize: 100
cacheRedisUrl:
cacheRedisConnectionPoolSize:
rejectQType:
  - 255

alternativeDNS根据需要也可自行选择国外的DNS服务

最后运行overture

Bash
# 1000以下特权端口需要root权限运行
sudo ./overture-linux-amd64 -c config.json

但是无论是CloudFlareDNS还是GoogleDNS都是无法直接访问的

我们可以在配置文件中填入socks5代理来处理这个问题

如果不方便填入socks5代理,也可以选择一台国外vps部署一个overture使用非53端口运行

最后将本地alternativeDNS指向这台国外vps即可(推荐)


[[replyMessage== null?"发表评论":"发表评论 @ " + replyMessage.m_author]]

account_circle
email
web_asset
textsms

评论列表([[messageResponse.total]])

还没有可以显示的留言...
[[messageItem.m_author]] [[messageItem.m_author]]
[[messageItem.create_time]]
[[getEnviron(messageItem.m_environ)]]
[[subMessage.m_author]] [[subMessage.m_author]] @ [[subMessage.parent_message.m_author]] [[subMessage.parent_message.m_author]]
[[subMessage.create_time]]
[[getEnviron(messageItem.m_environ)]]