Coder Social home page Coder Social logo

sina-ghaderi / nanodns Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 1.0 5 KB

simple dns forwarder/cache blocker server

Home Page: https://git.snix.ir

Go 100.00%
dns-server dns-forwarder dns-filter dns-blocking regex mikrotik golang raspberry-pi linux openwrt

nanodns's Introduction

Nano DNS

Simple and tiny DNS server written in Golang for filtering domains and speed up name resolution functionality.
Core features:
forward and cache dns queries
block domain names with regex.

Installation

Prerequisites: Golang + Git
Installing for windows - linux - freebsd and macos. (linux is recommended)
Clone the code form Github or Snix servers.

# git clone https://slc.snix.ir/snix/nanodns.git      # Snix
# git clone https://github.com/khokooli/nanodns.git   # Github  
# cd nanodns 
# go get -v
# go build
# ./nanodns
2020/07/31 05:11:29 upstream dns: 1.1.1.1:53 connection udp
2020/07/31 05:11:29 dns listen on: 0.0.0.0:53 connection udp
2020/07/31 05:11:29 load banned domains from: noacc.txt

Cross Compiles

If you want to build this for other device architectures (like Mikrotik, Raspberry pi) follow this.
Build for Mikrotik RB 2011 UIAS-IN runing on OpenWRT: (Mipsbe CPU)

# cd nanodns
# GOOS=linux GOARCH=mips GOMIPS=softfloat go build
# scp nanodns [email protected]:/root/

After all connect to your device and run the nanodns binary.
Building for Raspberry pi: (ARM64 CPU's)

cd nanodns
GOARCH=arm64 GOOS=linux go build

Usage and Options

# ./nanodns -h
Usage of ./nanodns:
  -fakeadd string
        an ip to send back for filtered domains <ipaddr> (default "127.0.0.1")
  -filter string
        filtered domains <filename> - regex is supported (default "noacc.txt")
  -loaddr string
        dns server listen address <ipaddr:port> (default "0.0.0.0:53")
  -loconn string
        dns server connection type <udp|tcp> (default "udp")
  -upaddr string
        upsteam dns server to connect <ipaddr:port> (default "1.1.1.1:53")
  -upconn string
        upsteam dns connection type <udp|tcp> (default "udp")

Regex Domain Blocking

You can use regex for blocking domain names, create a file like noacc.txt in nanodns directory.
For blocking all com and example.net put the following in noacc.txt
Regex Test Tool Online

^([a-z0-9]+[.])*com.$
example.net.

Block all domains if contain following words:
advertise, torrent or hack

^(torrent|hack|advertise).*$

Block any domain except google.com and snix.ir

^((?!google[.]com[.]|snix[.]ir[.]).)*$

Notes about regex in Golang:
Please note that if your regex string contain escape character '\' char, put another backslash befor it.
Read more about Escape Character.

^\babc\b.*$      ---> wrong
^\\babc\\b.*$    ---> it's ok

Support and Social Media

So if you interested to learn Golang follow my Instagram Account, Thanks.

nanodns's People

Contributors

sina-ghaderi avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

wsw70

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.