3
This script creates a DNS server that has enough functionality to test
4
the server autodiscovery feature of landscape client.
6
Landscape client uses /etc/resolv.conf to find the location of name servers.
7
To have landscape client use this server, make sure that:
11
is the first nameserver in /etc/resolv.conf. Linux name lookups only support
12
port 53, so this program must run on port 53 in order to work. Be aware that
13
NetworkManager overwrites this file any time your network configuration
16
This program does not return enough information for a tool like dig to complete
17
successfully. If this is needed, use Bind 9, detailed at
18
https://wiki.canonical.com/Landscape/SpecRegistry/0082
23
from twisted.internet import reactor, defer
24
from twisted.names import dns, common
25
from twisted.names.server import DNSServerFactory
29
SRV_RESPONSE = 'lds1.mylandscapehost.com'
30
A_RESPONSE = '127.0.0.1'
33
class SimpleResolver(common.ResolverBase):
34
def _lookup(self, name, cls, typ, timeout):
36
Respond to DNS requests. See documentation for
37
L{twisted.names.common.ResolverBase}.
39
# This nameserver returns the same result all the time, regardless
40
# of what name the client asks for.
44
record = dns.Record_SRV(0, 1, 80, SRV_RESPONSE, ttl)
45
owner = '_landscape._tcp.mylandscapehost.com'
46
results.append(dns.RRHeader(owner, record.TYPE, dns.IN, ttl,
49
record = dns.Record_A(A_RESPONSE)
50
owner = 'landscape.localdomain'
51
results.append(dns.RRHeader(owner, record.TYPE, dns.IN, ttl,
55
return defer.succeed((results, authority, []))
58
def parse_command_line(args):
59
global SRV_RESPONSE, A_RESPONSE, PORT
61
This test tool responds to DNS queries for SRV and A records. It always
62
responds with the same result regardless of the query string sent by the
65
To test this tool, try the following commands:
66
dig -p 5553 @127.0.0.1 SRV _landscape._tcp.mylandscapehost.com
68
dig -p 5553 @127.0.0.1 localhost.localdomain
70
parser = argparse.ArgumentParser(description=description)
71
parser.add_argument("--srv-response", type=str, default=SRV_RESPONSE,
72
help="Give this reply to SRV queries (eg: localhost)")
73
parser.add_argument("--a-response", type=str, default=A_RESPONSE,
74
help="Give this reply to A queries (eg: 127.0.0.1)")
75
parser.add_argument("--port", type=int, default=PORT,
76
help="Listen on this port (default 5553). DNS "
77
"normally runs on port 53")
79
args = vars(parser.parse_args())
80
SRV_RESPONSE = args["srv_response"]
81
A_RESPONSE = args["a_response"]
86
parse_command_line(sys.argv)
88
simple_resolver = SimpleResolver()
89
factory = DNSServerFactory(authorities=[simple_resolver], verbose=1)
90
protocol = dns.DNSDatagramProtocol(factory)
91
print "starting reactor on port %s.." % PORT
92
reactor.listenTCP(PORT, factory)
93
reactor.listenUDP(PORT, protocol)
95
print "reactor stopped..."
98
if __name__ == "__main__":