【瞎折腾】自建支持分线路解析的权威域名服务器

[post cid=”21” /]
接上文,使用 PowerDNS 搭建根服务器后,我又想尝试搭建权威域名服务器。

首先说一下我的观点:自建权威域名服务器犀利而无用。他要求高昂的成本但几乎没有回报。我的权威域名服务器是在两台我弃用的服务器上搭建的,因此可以无视成本。但我不建议各位这么做。

利用 PowerDNS 的 Lua 支持,我们可以轻松的搭建出一套支持分线路解析的 GeoDNS 服务器。
需要:

  • 一个 Maxmind 账户
  • 至少两台 VPS 服务器(目前域名服务商要求最少需要两个权威域名服务器)

配置地理信息库

  1. Maxmind 官网 获取账户的密钥,需要密钥来更新数据库。
  2. 安装geoipupdate 工具。
1
apt install geoipupdate
  1. 创建文件夹/etc/geoip,并修改/etc/GeoIP.conf
1
2
3
4
AccountID [账户编号]
LicenseKey [授权密钥]
EditionIDs GeoLite2-ASN GeoLite2-City GeoLite2-Country
DatabaseDirectory /etc/geoip
  1. 用 Cron 设置上自动更新:
1
2
3
crontab -e
# 加上一行:
0 0 * * 0 /usr/bin/geoipupdate
  1. 安装 GeoIP 后端
1
apt install -y pdns-backend-geoip
  1. 修改配置文件/etc/powerdns/pdns.conf
1
2
3
enable-lua-records=yes
launch=gmysql,geoip
geoip-database-files=/etc/geoip/GeoLite2-City.mmdb

配置 GeoDNS

在 PowerDNS Lua 中,用户的 IP 地址作为一个变量bestwho存在。不过如果用户的 DNS 服务器没有告知上游服务器用户的地址,那么bestwho就会指向 DNS 服务器的地址。
PowerDNS 提供了一个 lua 函数pickclosest,该函数从一个 IP 列表中选择离bestwho地理位置最近的服务器返回。
还有一个函数country,可以分辨国家。
两者的使用:

1
2
A "pickclosest({'1.1.1.1','8.8.8.8','114.114.114.114','223.5.5.5'})"
A ";if(country('CN')) then return '223.5.5.5' else return '1.1.1.1' end"

【瞎折腾】自建支持分线路解析的权威域名服务器

https://omn.cc/archives/22.html

作者

空指针

发布于

2023-11-05

更新于

2023-11-05

许可协议

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

评论

You forgot to set the shortname for Disqus. Please set it in _config.yml.
Your browser is out-of-date!

Update your browser to view this website correctly.&npsb;Update my browser now

×