• Stars
    star
    704
  • Rank 61,723 (Top 2 %)
  • Language
    Ruby
  • Created about 13 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A DSL for building fun, high-performance DNS servers.

RubyDNS

RubyDNS is a high-performance DNS server which can be easily integrated into other projects or used as a stand-alone daemon. By default it uses rule-based pattern matching. Results can be hard-coded, computed, fetched from a remote DNS server or fetched from a local cache, depending on requirements.

Build Status Code Climate Coverage Status Gitter

RubyDNS Introduction

Installation

Add this line to your application's Gemfile:

gem 'rubydns'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rubydns

Usage

There are lots of examples available in the examples/ directory.

Basic DNS Server

Here is the code from examples/basic-dns.rb:

#!/usr/bin/env ruby
require 'rubydns'

INTERFACES = [
	[:udp, "0.0.0.0", 5300],
	[:tcp, "0.0.0.0", 5300],
]

IN = Resolv::DNS::Resource::IN

# Use upstream DNS for name resolution.
UPSTREAM = RubyDNS::Resolver.new([[:udp, "8.8.8.8", 53], [:tcp, "8.8.8.8", 53]])

# Start the RubyDNS server
RubyDNS::run_server(INTERFACES) do
	match(%r{test.local}, IN::A) do |transaction|
		transaction.respond!("10.0.0.80")
	end

	# Default DNS handler
	otherwise do |transaction|
		transaction.passthrough!(UPSTREAM)
	end
end

Start the server using RUBYOPT=-w ./examples/basic-dns.rb. You can then test it using dig:

$ dig @localhost -p 5300 test.local
$ dig @localhost -p 5300 google.com

File Handle Limitations

On some platforms (e.g. Mac OS X) the number of file descriptors is relatively low by default and should be increased by calling ulimit -n 10000 before running tests or even before starting a server which expects a large number of concurrent incoming connections.

Custom Servers

It is possible to create and integrate your own custom servers, however this functionality has now moved to Async::DNS::Server.

class MyServer < Async::DNS::Server
	def process(name, resource_class, transaction)
		transaction.fail!(:NXDomain)
	end
end

Async::Reactor.run do
	task = MyServer.new.run
	
	# ... do other things, e.g. run specs/tests
	
	# Shut down the server manually if required, otherwise it will run indefinitely.
	# task.stop
end

This is the best way to integrate with other projects.

Performance

Due to changes in the underlying code, there have been some very minor performance regressions. The numbers below will be updated in due course.

We welcome additional benchmarks and feedback regarding RubyDNS performance. To check the current performance results, consult the travis build job output.

Server

The performance is on the same magnitude as bind9. Some basic benchmarks resolving 1000 names concurrently, repeated 5 times, using RubyDNS::Resolver gives the following:

                           user     system      total        real
RubyDNS::Server        4.280000   0.450000   4.730000 (  4.854862)
Bind9                  4.970000   0.520000   5.490000 (  5.541213)

These benchmarks are included in the unit tests. To test bind9 performance, it must be installed and which named must return the executable.

Resolver

The RubyDNS::Resolver is highly concurrent and can resolve individual names as fast as the built in Resolv::DNS resolver. Because the resolver is asynchronous, when dealing with multiple names, it can work more efficiently:

                           user     system      total        real
RubyDNS::Resolver      0.020000   0.010000   0.030000 (  0.030507)
Resolv::DNS            0.070000   0.010000   0.080000 (  1.465975)

These benchmarks are included in the unit tests.

DNSSEC support

DNSSEC is currently not supported and is unlikely to be supported in the future.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Desired Features

  • Support for more features of DNS such as zone transfer.
  • Support reverse records more easily.
  • Some kind of system level integration, e.g. registering a DNS server with the currently running system resolver.

See Also

The majority of this gem is now implemented by async-dns.

  • async-io — Asynchronous networking and sockets.
  • async-dns — Asynchronous DNS resolver and server.
  • async-rspec — Shared contexts for running async specs.

License

Released under the MIT license.

Copyright, 2017, by Samuel G. D. Williams.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

More Repositories

1

falcon

A high-performance web server for Ruby, supporting HTTP/1, HTTP/2 and TLS.
Ruby
2,427
star
2

async

An awesome asynchronous event-driven reactor for Ruby.
Ruby
1,937
star
3

nio4r

Cross-platform asynchronous I/O primitives for scalable network clients and servers.
C
954
star
4

cool.io

Simple evented I/O for Ruby (but please check out Celluloid::IO instead)
C
694
star
5

timers

Pure Ruby timers collections suitable for use with event loops
Ruby
334
star
6

multipart-post

Adds multipart POST capability to net/http
Ruby
288
star
7

async-http

Ruby
280
star
8

localhost

Ruby
204
star
9

async-io

Concurrent wrappers for native Ruby IO & Sockets.
Ruby
199
star
10

lightio

LightIO is a userland implemented green thread library for ruby
Ruby
163
star
11

async-websocket

Asynchronous WebSocket client and server, supporting HTTP/1 and HTTP/2 for Ruby.
Ruby
143
star
12

utopia

A content-centric Ruby/Rack based web framework.
Ruby
136
star
13

cloudflare

An asynchronous Ruby wrapper for the CloudFlare V4 API.
Ruby
135
star
14

socketry

High-level wrappers for Ruby sockets with advanced thread-safe timeout support
Ruby
132
star
15

async-dns

An asynchronous DNS resolver and server.
Ruby
92
star
16

http-accept

Parse Accept and Accept-Language HTTP headers in Ruby.
Ruby
80
star
17

async-postgres

Ruby
78
star
18

async-redis

Ruby
76
star
19

async-await

Why wait? It's available today!
Ruby
68
star
20

async-container

Scalable multi-thread multi-process containers for Ruby.
Ruby
67
star
21

async-http-faraday

Ruby
67
star
22

async-rspec

Ruby
51
star
23

rackula

Generate a static site from any rack middleware.
Ruby
51
star
24

io-event

C
50
star
25

db

Event-driven database drivers for streaming queries.
Ruby
48
star
26

console

Ruby
47
star
27

live

JavaScript
46
star
28

roda-websockets

Asynchronous WebSockets plugin for Roda.
Ruby
44
star
29

process-metrics

Ruby
33
star
30

db-postgres

Ruby
32
star
31

async-rest

Ruby
29
star
32

async-pool

Provides support for connection pooling both singleplex and multiplex resources.
Ruby
23
star
33

async-job

Ruby
21
star
34

guard-falcon

Ruby
21
star
35

async-process

Ruby
20
star
36

async-actor

Ruby
18
star
37

protocol-http

Ruby
18
star
38

utopia-project

JavaScript
18
star
39

falcon-capybara

Ruby
18
star
40

benchmark-http

Ruby
17
star
41

rspec-memory

Ruby
15
star
42

falcon-rails-example

Ruby
15
star
43

async-examples

Ruby
14
star
44

traces

Ruby
14
star
45

cloudflare-dns-update

A Ruby script which can update CloudFlare periodically to provide dynamic DNS.
Ruby
14
star
46

thread-local

Ruby
13
star
47

async-sequel

Ruby
13
star
48

lively

JavaScript
13
star
49

fiber-local

Ruby
13
star
50

async-mysql

Ruby
12
star
51

falcon-benchmark

A work in progress synthetic benchmark comparing Falcon with other servers.
JavaScript
10
star
52

db-mariadb

Ruby
10
star
53

protocol-quic

C++
9
star
54

protocol-websocket

Provides a low-level implementation of the WebSocket protocol according to RFC6455.
Ruby
8
star
55

variant

Ruby
8
star
56

protocol-http2

Ruby
7
star
57

rack-conform

Ruby
7
star
58

async-limiter

Async limiter for ruby.
Ruby
7
star
59

metrics

Ruby
7
star
60

async-job-rails-example

Ruby
7
star
61

async-job-adapter-active_job

Ruby
6
star
62

async-webdriver

Ruby
6
star
63

async-worker

Ruby
5
star
64

memory

Ruby
5
star
65

async-http-cache

Ruby
5
star
66

protocol-http1

Ruby
5
star
67

db-active_record

Ruby
5
star
68

db-model

Ruby
4
star
69

async-debug

JavaScript
4
star
70

falcon-my_api

Ruby
3
star
71

protocol-hpack

Ruby
3
star
72

katacoda

Katacoda Tutorials
Shell
3
star
73

community

3
star
74

traces-backend-datadog

Ruby
3
star
75

async-bus

Ruby
3
star
76

live-js

JavaScript
3
star
77

migrate

Ruby
3
star
78

utopia-falcon-heroku

JavaScript
3
star
79

console-adapter-rails

Ruby
2
star
80

rails-falcon-heroku

Ruby
2
star
81

io-stream

Ruby
2
star
82

lively-falcon

Ruby
2
star
83

protocol-rack

Ruby
2
star
84

async-cable

Ruby
2
star
85

utopia-wiki

JavaScript
1
star
86

rspec-files

Ruby
1
star
87

console-adapter-sidekiq

Ruby
1
star
88

console-output-datadog

Ruby
1
star
89

sus-fixtures-openssl

Ruby
1
star
90

db-migrate

Ruby
1
star
91

metrics-backend-datadog

Ruby
1
star
92

traces-backend-open_telemetry

Ruby
1
star
93

async-service

Ruby
1
star
94

falcon-example-sinatra

Ruby
1
star
95

process-terminal

Ruby
1
star
96

async-slack

Ruby
1
star
97

xrb-rails

Ruby
1
star