Giter VIP home page Giter VIP logo

blocker's Introduction

blocker - Domain blocker plugin for CoreDNS

blocker is a CoreDNS plugin which can be used to block a list of domains provided in the /etc/hosts file format. The blocklist will be loaded into memory at start-up and the file’s modified time will be checked periodically. When the blocklist file is updated, the in-memory blocklist will be updated by scanning the blocklist file.

Updating the blocklist file is beyond the scope of this plugin. I recommend a bash script which downloads common blocklists and updates them into a format without comments. The script blocklist-file-preparer.sh included with this repository is an example of how this can be done using bash and GNU utils.

Example blocklist file: (AdBlock Plus syntax)

||buyer.revsci.net^
||ww92.impfr.tradedoubler.com^
||next.chartboost.com^
||pl16442154.alternativecpmgate.com^
||denturesauaid.com^
||pdx-p-con-336.saas.appdynamics.com^
||cdn.ad.citynews.it^
||xxxxxxxamob.acs86.com^
||www.globalhotsale.su^
||zipuploads.com^

Usage

CoreDNS Binary

You can include blocker in your CoreDNS just as you would include any other CoreDNS plugin.

# Clone coredns to a local location
$ git clone [email protected]:coredns/coredns.git ~/dns-server/coredns

# Clone blocker plugin to a close location
$ git clone [email protected]:icyflame/blocker.git ~/dns-server/blocker

# Symlink blocker location into coredns/plugin/blocker
$ cd ~/dns-server/coredns/plugin
$ ln -s ../blocker ./blocker

# Update plugin.cfg and put the line "blocker:blocker" before the "forward:forward" line

# Build CoreDNS
$ cd ~/dns-server/coredns
$ go generate
$ make
$ ./coredns -conf Corefile

Corefile

The blocker directive inside Corefile requires two arguments. The first argument is the absolute path to the blocklist file. The second argument is the frequency at which the blocklist file is checked for updates.

The frequency is specified as a string and the value should be a valid argument to the time.ParseDuration function.

blocker /home/user/blocklist_file 1h abp

This is a sample Corefile including the blocker directive. It will block domains that are specified in the blocklist and forward everything else to a full DNS server.

 .:53 {
	metadata

	# prometheus records metrics regarding incoming requests
	prometheus

	# log writes 1 line to the log for every DNS request
	# The last word in the log line will be YES if the request was blocked and NO if it was not
	# blocked.
	# This behaviour is supported by the metadata plugin.
	log . "{common} {/blocker/request-blocked}"

	# blocker blocks domains which are specified in the blocklist
	blocker /home/user/blocklist_file 1h hosts

	# forward handles any request that is not blocked by blocker
	forward . 127.0.0.1:9053
 }

plugin.cfg

This is a sample middleware configuration file. The order of plugins here is important. This is the order in which plugins will be executed for incoming requests.

metadata:metadata
prometheus:metrics
log:log
blocker:blocker
forward:forward

Interaction with Other CoreDNS Plugins

metadata

The blocker plugin will write the metadata value with the label blocker/request-blocked. This is a boolean value whose value will be either YES (if the request was blocked and the empty IP address was returned as a result to the user) and NO when the request was not blocked.

blocker's People

Contributors

icyflame avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.