You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This guide explains how to get started running your own DNS server with RubyDNS.
4
+
5
+
## Installation
6
+
7
+
Create a new directory for your project, with a gemfile, and then add the gem to your project:
8
+
9
+
~~~bash
10
+
$ bundle add rubydns
11
+
~~~
12
+
13
+
## Usage
14
+
15
+
### Simple DNS Server
16
+
17
+
This example demonstrates how to create a simple DNS server that responds to `test.local A` and forwards all other requests to the system default resolver.
18
+
19
+
```ruby
20
+
#!/usr/bin/env ruby
21
+
require'rubydns'
22
+
23
+
# Use the system default resolver for upstream queries:
24
+
upstream =Async::DNS::Resolver.default
25
+
26
+
# We will use port 5300 so we don't need to run the server as root:
match(%r{test.local}, Resolv::DNS::Resource::IN::A) do |transaction|
32
+
transaction.respond!("10.0.0.80")
33
+
end
34
+
35
+
# Default DNS handler
36
+
otherwise do |transaction|
37
+
transaction.passthrough!(upstream)
38
+
end
39
+
end
40
+
```
41
+
42
+
### Custom Servers
43
+
44
+
It is possible to create and integrate your own custom servers, however this functionality has now moved to [`Async::DNS::Server`](https://github.com/socketry/async-dns).
45
+
46
+
```ruby
47
+
classMyServer < Async::DNS::Server
48
+
defprocess(name, resource_class, transaction)
49
+
transaction.fail!(:NXDomain)
50
+
end
51
+
end
52
+
53
+
Asyncdo
54
+
task =MyServer.new.run
55
+
56
+
# ... do other things, e.g. run specs/tests
57
+
58
+
# Shut down the server manually if required, otherwise it will run indefinitely.
59
+
# task.stop
60
+
end
61
+
```
62
+
63
+
This is the best way to integrate with other projects.
There are examples in the `examples` directory which demonstrate how to use RubyDNS.
18
10
19
-
### Simple DNS Server
20
-
21
-
This example demonstrates how to create a simple DNS server that responds to `test.local A` and forwards all other requests to the system default resolver.
22
-
23
-
```ruby
24
-
#!/usr/bin/env ruby
25
-
require'rubydns'
26
-
27
-
# Use the system default resolver for upstream queries:
28
-
upstream =Async::DNS::Resolver.default
29
-
30
-
# We will use port 5300 so we don't need to run the server as root:
match(%r{test.local}, Resolv::DNS::Resource::IN::A) do |transaction|
36
-
transaction.respond!("10.0.0.80")
37
-
end
38
-
39
-
# Default DNS handler
40
-
otherwise do |transaction|
41
-
transaction.passthrough!(upstream)
42
-
end
43
-
end
44
-
```
45
-
46
-
### Custom Servers
47
-
48
-
It is possible to create and integrate your own custom servers, however this functionality has now moved to [`Async::DNS::Server`](https://github.com/socketry/async-dns).
49
-
50
-
```ruby
51
-
classMyServer < Async::DNS::Server
52
-
defprocess(name, resource_class, transaction)
53
-
transaction.fail!(:NXDomain)
54
-
end
55
-
end
56
-
57
-
Asyncdo
58
-
task =MyServer.new.run
59
-
60
-
# ... do other things, e.g. run specs/tests
61
-
62
-
# Shut down the server manually if required, otherwise it will run indefinitely.
63
-
# task.stop
64
-
end
65
-
```
66
-
67
-
This is the best way to integrate with other projects.
68
-
69
-
### DNSSEC support
70
-
71
-
DNSSEC is currently not supported and is [unlikely to be supported in the future](http://sockpuppet.org/blog/2015/01/15/against-dnssec/).
72
-
73
11
## See Also
74
12
75
13
The majority of this gem is now implemented by `async-dns`.
0 commit comments