Giter Club home page Giter Club logo

lightdns's Introduction

lightdns

This is a light weight DNS Server which serves A type record for now.

Installation

go get github.com/openmohan/lightdns

Requirements

  • Go 1.90

Usage

  1. Import the package lightdns "github.com/openmohan/lightdns"
  2. Create a DNS Server dns := lightdns.NewDNSServer(port_int)
  3. Add Zone data using the function AddZoneData

dns.AddZoneData(zone, staticRecords, lookupFunction, ZoneType)

Example

If the records data available we can code it and Add the zone data

	var googleRecords = map[string]string{
		"mail.google.com":  "192.168.0.2",
		"paste.google.com": "192.168.0.3",
	}
	dns.AddZoneData("google.com", googleRecords, nil, lightdns.DNSForwardLookupZone)

or

If the data is not static and has to be taken from a DB or from any other sources or calculated dynamically then use lookup function. Define a lookup function in the format

func lookupFunc(domain string) (ip string, err error) ie: given a domain name string as parameter, IP string and error value has to be returned.

	func lookupFunc(string) (string, error) {
		//Do some action
		//Get data from DB
		//Process it further more
		return "192.2.2.1", nil
	}
	dns.AddZoneData("amazon.com", nil, lookupFunc, lightdns.DNSForwardLookupZone)
  1. Start the DNS Server by dns.StartAndServe()

Complete Example

package main

import (
	lightdns "github.com/openmohan/lightdns"
)

var records = map[string]string{
	"mail.amazon.com":  "192.162.1.2",
	"paste.amazon.com": "191.165.0.3",
}

func lookupFunc(string) (string, error) {
	//Do some action
	//Get data from DB
	//Process it further more
	return "192.2.2.1", nil
}

func main() {
	var googleRecords = map[string]string{
		"mail.google.com":  "192.168.0.2",
		"paste.google.com": "192.168.0.3",
	}
	var microsoftRecords = map[string]string{
		"mail.microsoft.com":  "192.168.0.78",
		"paste.microsoft.com": "192.168.0.25",
	}
	dns := lightdns.NewDNSServer(1234)
	dns.AddZoneData("google.com", googleRecords, nil, lightdns.DNSForwardLookupZone)
	dns.AddZoneData("microsoft.com", microsoftRecords, nil, lightdns.DNSForwardLookupZone)

	/* Incase if the records are not static or to be taken from DB or from any other sources
	lookupFunc method can be used.append*/
	dns.AddZoneData("amazon.com", nil, lookupFunc, lightdns.DNSForwardLookupZone)
	dns.StartAndServe()
}

Work in progress

Support for

  1. MX, AAAA, SOA and other records
  2. Reverse lookup zone

Code

  1. Use goroutines for optimizing the speed
  2. Unit Test Cases
  3. Logging mechanism for monitoring and debugging
  4. Error handling

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

License

MIT

lightdns's People

Contributors

openmohan avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

lightdns's Issues

TXT records?

thanks for creating the DNS server.
will you be supporting TXT records as well?
They'd be used in let's encrypt SSL for wildcard subdomains

How can I measure the performance of the DNS Server?

Thanks for the tool!! Is there a way to measure the performance of the DNS Server? So that it would be helpful for us to compare it with the existing tools.

I tried namebench - https://namebench.en.softonic.com/mac, grc - https://www.grc.com/dns/benchmark.htm

But both the tools are very old and it is not supported in the recent version of mac (because both are 32 bit applications available for windows, so wine also didn t work for me).

Please let me know if there is any way to measure the performance of local DNS server. It would be helpful.

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.