PowerDNS LUA Install
Jump to navigation
Jump to search
#!/usr/bin/env bash set -ex systemctl stop systemd-resolved touch /etc/dnsmasq.hosts systemctl disable systemd-resolved systemctl mask systemd-resolved rm /etc/resolv.conf # sed -i 's/nameserver.*/nameserver 8.8.8.8/' /etc/resolv.conf # echo "nameserver 8.8.8.8" > /etc/resolv.conf echo "nameserver 10.64.4.1" > /etc/resolv.conf # options edns0 trust-ad db_name=pdns db_user=pdns db_pass=pdns export PGPASSWORD="pdns" . /etc/os-release echo "deb [arch=amd64] http://repo.powerdns.com/$ID $VERSION_CODENAME-auth-master main" > /etc/apt/sources.list.d/pdns.list echo "Package: pdns-* Pin: origin repo.powerdns.com Pin-Priority: 600" > /etc/apt/preferences.d/pdns sudo apt-get update sudo apt install postgresql-12 curl https://repo.powerdns.com/CBC8B383-pub.asc | sudo apt-key add - && sudo apt-get update && sudo apt-get install -y pdns-server pdns-backend-pgsql # sudo -i -u postgres dropdb -h 127.0.0.1 -U pdns pdns # sudo -i -u postgres dropdb -h 127.0.0.1 pdns # sudo -i -u postgres psql -c "DROP SCHEMA pdns CASCADE" || true systemctl stop pdns sudo -i -u postgres psql -c "DROP DATABASE $db_name" || true # sudo -i -u postgres psql -c "DROP OWNED BY pdns; DROP ROLE pdns" || true # sudo -i -u postgres psql -c "DROP OWNED BY pdns; DROP ROLE pdns" || true sudo -i -u postgres psql -c "DROP OWNED BY $db_user CASCADE" || true sudo -i -u postgres psql -c "DROP ROLE $db_user" || true sudo -i -u postgres psql -c "CREATE ROLE $db_user WITH SUPERUSER CREATEDB CREATEROLE LOGIN ENCRYPTED PASSWORD '$db_pass'" # sudo -i -u postgres psql password=$db_pass -c "CREATE DATABASE $db_name OWNER $db_user" sudo -i -u postgres psql -c "CREATE DATABASE $db_name OWNER $db_user" # sudo -i -u postgres createdb -O pdns pdns # sudo psql -U pdns -W -h 127.0.0.1 pdns < /usr/share/pdns-backend-pgsql/schema/schema.pgsql.sql # sudo psql -U pdns -W password=$db_pass -c -h 127.0.0.1 pdns < /usr/share/doc/pdns-backend-pgsql/schema.pgsql.sql sudo psql -U pdns password=$db_pass -h 127.0.0.1 pdns < /usr/share/doc/pdns-backend-pgsql/schema.pgsql.sql sudo psql -U pdns password=$db_pass -h 127.0.0.1 pdns < /root/luadns.sql # cp -p /usr/share/doc/pdns-backend-pgsql/examples/pdns.local.gpgsql.conf /etc/powerdns/pdns.d/ echo "enable-lua-records=yes # PostgreSQL Configuration # # Launch gpgsql backend launch+=gpgsql # gpgsql parameters gpgsql-host=127.0.0.1 gpgsql-port=5432 gpgsql-dbname=pdns gpgsql-user=pdns gpgsql-password=pdns gpgsql-dnssec=yes" > /etc/powerdns/pdns.d/pdns.local.gpgsql.conf systemctl start pdns systemctl status pdns systemctl status postgresql dig +short www.example.com @127.0.0.1
/root/luadns.sql
INSERT INTO domains (name, type) values ('example.com', 'NATIVE'); -- INSERT INTO domains (id, name, type) VALUES (1, 'example.com', 'NATIVE'); INSERT INTO records (domain_id, name, content, type,ttl,prio) VALUES (1,'example.com','localhost admin.example.com 1 10380 3600 604800 3600','SOA',86400,NULL); INSERT INTO records (domain_id, name, content, type,ttl,prio) VALUES (1,'example.com','dns-us1.powerdns.net','NS',86400,NULL); INSERT INTO records (domain_id, name, content, type,ttl,prio) VALUES (1,'example.com','dns-eu1.powerdns.net','NS',86400,NULL); INSERT INTO records (domain_id, name, content, type,ttl,prio) VALUES (1,'www.example.com','192.0.2.10','A',120,NULL); INSERT INTO records (domain_id, name, content, type,ttl,prio) VALUES (1,'mail.example.com','192.0.2.12','A',120,NULL); INSERT INTO records (domain_id, name, content, type,ttl,prio) VALUES (1,'localhost.example.com','127.0.0.1','A',120,NULL); INSERT INTO records (domain_id, name, content, type,ttl,prio) VALUES (1,'example.com','mail.example.com','MX',120,25); -- Enable Lua records for the zone (if not enabled globally) INSERT INTO domainmetadata (domain_id, kind, content) VALUES (1, 'ENABLE-LUA-RECORDS', 1); -- Create a pickClosest() Lua A record. -- Double single quotes are used to escape single quotes in both MySQL and PostgreSQL INSERT INTO records (domain_id, name, type, content, ttl) VALUES ( 1, 'pickclosest.example.com', 'LUA', 'A "pickclosest({''192.0.2.1'',''192.0.2.2'',''198.51.100.1''})"', 600 ); INSERT INTO records (domain_id, name, type, content, ttl) VALUES ( 1, 'ifurlup.example.com', 'LUA', 'A "ifurlup(''https://www.uvoo.io/'', {''x.x.x.z'', ''x.x.x.y''})"', 600 );