Total Pageviews

Sunday, 14 July 2019

dns解析服务器程序:Marco Polo DNS Daemon


Intro

Marco Polo DNS Daemon is a DNS server, which can return different CNAME record based on DNS resolver's IP address and edns-client-subnet information.
Currently it supports three types: AS Number, Country Code, and Random.

Install

Install the following dependencies:
  • libfile-write-rotate-perl (File::Write::Rotate)
  • libgeo-ip-perl (Geo::IP)
  • libnet-dns-perl (Net::DNS) - Version 0.68 on Ubuntu 14.04 and eariler one are not new enough to work
  • geoip-database-contrib
Then just copy lib/mpdnsd.pm into /usr/sbin/mpdnsd.

Run

/usr/sbin/mpdnsd \
    [--bind_host IP1,IP2,...] \
    [--cpu CPU] \
    [--nsrrs NS1.DOMAIN,NS2.DOMAIN,...] \
    [--port PORT] \
    [--querylog_file FILENAME] \
    [--service_domain SERVICE.DOMAIN] \
    [--ttl_asn SECONDS] \
    [--ttl_country SECONDS] \
    [--ttl_ns SECONDS] \
    [--ttl_random SECONDS] \
    [--whitelist_domain ONE.MP.DOMAIN,TWO.MP.DOMAIN]
For example:
/usr/sbin/mpdnsd \
    --bind_host 0.0.0.0 \
    --nsrrs mp-ns1.example.com,mp-ns2.example.com \
    --service_domain mp.example.com \
    --whitelist_domain example.com

Use

You can get AS number by this example:
dig test.example.com.asn.mp.example.com @mp-ns1.example.com
It will return a CNAME record to:
12345.test.example.com
Which 12345 is AS number based on client's DNS resolver or edns-client-subnet information.
Also, you can get country code:
dig test.example.com.country.mp.example.com @mp-ns1.example.com
TW.test.example.com
And you can get the utc hour:
dig test.example.com.hour.mp.example.com
9.test.example.com
And you can choose randomly for range [0..10) (i.e. 0~9):
dig test.example.com.r10.mp.example.com
9.test.example.com

Test

perl Build.PL
./Build testcover
  from https://github.com/KKBOX/mpdnsd-perl

No comments:

Post a Comment