以ubuntu20.04为例
开源地址:https://github.com/PowerDNS/pdns
按上面教程可以编译直接使用,但不能实现分省分线路解析,需要自行编译,还得改文件
先到打开https://dev.maxmind.com/geoip/geoip2/geolite2/
分省解析需要下载:GeoLite2-City.mmdb 这个数据库
分线路线解析需要下载: GeoLite2-ISP.mmdb (收费的,$24,如果你不需要更新,买一次就可以了)
下载好放到/etc/geoip
一、安装依赖
apt install libcurl4-openssl-dev luajit lua-yaml-dev libyaml-cpp-dev libtolua-dev lua5.3 autoconf automake ragel bison flex g++ libboost-all-dev libtool make pkg-config libssl-dev lua-yaml-dev libyaml-cpp-dev libluajit-5.1-dev libcurl4 gawk libsqlite3-dev python3-venvapt install libsodium-devapt install default-libmysqlclient-devapt install libpq-devapt install libsystemd0 libsystemd-devapt install libmaxminddb-dev libmaxminddb0 libgeoip1 libgeoip-devapt install lua*
二、克隆仓库
git clone https://github.com/PowerDNS/pdns.git把我附件修改过的代码覆盖到 modules/geoipbackend执行编译./configure --prefix=/usr/local/powerdns --enable-verbose-logging --enable-static-binaries --enable-pdns_server --enable-nedmalloc --with-libcurl --with-maxminddb-includedir --with-maxminddb-libdir --with-lua --with-modules='gmysql geoip lua2 bind'makemake install
三、建立数据库
把附件的数据导入执行(注意:这个库和官方的有改动,我把表放到内存中运行了,所以重启数据库记录会消失,我是多台服务器做主从了,不怕丢失)
停止系统默认DNS解析器,防止53端口占用
#停止 DNSStubListenersystemctl stop systemd-resolvedecho "nameserver 8.8.8.8" > /etc/resolv.confcat > /usr/local/powerdns/etc/pdns.conf<<EOF[Unit]enable-lua-records=yesgmysql-host=127.0.0.1#mysql帐号gmysql-user=root#mysql密码gmysql-password=123456#mysql数据库gmysql-dbname=pdnslocal-address=0.0.0.0:53api=yesapi-key=rthqnglamaorrivu# IP Address of web server to listen onwebserver-address=0.0.0.0# Port of web server to listen onwebserver-port=62888# Web server access is only allowed from these subnetswebserver-allow-from=0.0.0.0/0,::/0# Needed before 4.1.0webserver=yeslaunch=gmysql,geoip#以下三个参数为调试使用log-dns-details=yeslog-dns-queries=yesloglevel=6#是否放到后台运行#daemon=yesgeoip-database-files=/etc/geoip/GeoIP2-ISP.mmdbEOFln -s /usr/local/powerdns/sbin/pdns_server /usr/sbin/pdns_server
四、运行
/usr/sbin/pdns_server --socket-dir=/run/pdns --guardian=no --daemon=no --disable-syslog --log-timestamp=no --write-pid=no
如果没意外服务端就好了
五、LUA数据库插件安装
$ wget http://luarocks.org/releases/luarocks-2.2.1.tar.gz$ tar zxpf luarocks-2.2.1.tar.gz$ cd luarocks-2.2.1$ ./configure; sudo make bootstrap$ sudo luarocks install luasql-mysql$ luaLua 5.3.0 Copyright (C) 1994-2015 Lua.org, PUC-Rio> require "socket"Lua 5.3.0 Copyright (C) 1994-2015 Lua.org, PUC-Rio
六、
WEB 端下载
https://www.poweradmin.org/ 直接安装就行了
安装完后替换
inc/toolkit.inc.php 和 inc/dns.inc.php 增加LUA
然后登陆 点上方的Add master zone添加域名
点List zones 管理域名解析
使用LUA增加分线路解析示示例
5和10的取值于geoipinterface.hh:enum GeoIPQueryAttribute { ASn, #0 City, #1 Continent, #2 Country, #3 Country2, #4 Name, #5 Region, Location, autonomousSystemNumber, autonomousSystemOrganization, isp, #10 organization };
其他:
LUA 参考:https://doc.powerdns.com/authoritative/lua-records/
API 参考(就是62888那个API端口): https://doc.powerdns.com/md/httpapi/README/
归档.zip
相关推荐:
#开源# 为DNSmasq写了一个WEB界面PHPDNS
作者id:奧巴