linux机器搭建个人DNS教程,可实现省解析,分线路解析
以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-venv apt install libsodium-dev apt install default-libmysqlclient-dev apt install libpq-dev apt install libsystemd0 libsystemd-dev apt install libmaxminddb-dev libmaxminddb0 libgeoip1 libgeoip-dev apt 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' make make install
三、建立数据库
把附件的数据导入执行(注意:这个库和官方的有改动,我把表放到内存中运行了,所以重启数据库记录会消失,我是多台服务器做主从了,不怕丢失)
停止系统默认DNS解析器,防止53端口占用
#停止 DNSStubListener systemctl stop systemd-resolved echo "nameserver 8.8.8.8" > /etc/resolv.conf cat > /usr/local/powerdns/etc/pdns.conf<<EOF [Unit] enable-lua-records=yes gmysql-host=127.0.0.1 #mysql帐号 gmysql-user=root #mysql密码 gmysql-password=123456 #mysql数据库 gmysql-dbname=pdns local-address=0.0.0.0:53 api=yes api-key=rthqnglamaorrivu # IP Address of web server to listen on webserver-address=0.0.0.0 # Port of web server to listen on webserver-port=62888 # Web server access is only allowed from these subnets webserver-allow-from=0.0.0.0/0,::/0 # Needed before 4.1.0 webserver=yes launch=gmysql,geoip #以下三个参数为调试使用 log-dns-details=yes log-dns-queries=yes loglevel=6 #是否放到后台运行 #daemon=yes geoip-database-files=/etc/geoip/GeoIP2-ISP.mmdb EOF ln -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 $ lua Lua 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/
相关推荐:
作者id:奧巴