Quantcast
Viewing all articles
Browse latest Browse all 6168

bind9 server to forward zones to an external DNS server

I want to build a CDN platform for a project, and for the load balancing part, I decided to use a bind9 server to forward zones to an external DNS server, where I'll also handle the load balancing. The issue is that my custom DNS server perceives the requests and sends responses to bind9, but bind9 doesn't process the response.

req ('3.91.51.202', 56626) b'\\x02\x01\x10\x00\x01\x00\x00\x00\x00\x00\x01\x04idoc\x02ro\x00\x00\x01\x00\x01\x00\x00)\x04\xd0\x00\x00\x80\x00\x00\x0c\x00\n\x00\x08\xd8!A\xc6\xebES\x14'id 1474qr 0opcode 0aa 0tc 0rd 1z 1Rcode 0qdcount 1ancount 0nscount 0arcount 1DOMAIN: idoc.roqtype 1qclass 1ip [192, 168, 1, 232]resp b'\\x02\x85\x10\x00\x00\x00\x01\x00\x00\x00\x00\x04idoc\x02ro\x00\x00\x01\x00\x01\x00\x00\x00\n\x00\x04\xc0\xa8\x01\xe8'

DNS server custom

def handle_request(args):    server_socket, buf, client_address = args    # Codul pentru tratarea cererii DNS    print("Procesez cererea de la ", client_address, buf)    print(f"id {(buf[0] & 0xff) * 16 + (buf[1] & 0xff)}")    print(f"qr {(buf[2] & 0x80) >> 7}")    print(f"opcode {(buf[2] & 0x78) >> 3}")    print(f"aa {(buf[2] & 0x04) >> 2}")    print(f"tc {(buf[2] & 0x02) >> 1}")    print(f"rd {(buf[2] & 0x01)}")    print(f"z {(buf[3] & 0x70) >> 4}")    print(f"Rcode {(buf[3] & 0x0f)}")    print(f"qdcount {((buf[4] & 0xff) * 16 + (buf[5] & 0xff))}")    print(f"ancount {((buf[6] & 0xff) * 16 + (buf[7] & 0xff))}")    print(f"nscount {((buf[8] & 0xff) * 16 + (buf[9] & 0xff))}")    print(f"arcount {((buf[10] & 0xff) * 16 + (buf[11] & 0xff))}")    domain = bytearray()    for i in range(13, len(buf)):        if buf[i] == 0:            break        domain.append(buf[i])    k = buf[12]    for i in range(len(domain)):        if i == k:            k = i + domain[i] + 1            domain[i] = 0x2e    domain_bytes = bytes(domain)    print("DOMAIN:", domain.decode('utf-8'))    print(f"qtype {((buf[14 + len(domain)] & 0xff) * 16 + (buf[15 + len(domain)] & 0xff))}")    print(f"qclass {((buf[16 +len(domain)] & 0xff) * 16 + (buf[17 + len(domain)] & 0xff))}")    #Response    resp = bytearray(28 + len(domain_bytes))    for i in range(4):        resp[i] = buf[i]    resp[2] |= 0x84 # qr 1    resp[3] &= 0xF0 # rcode 1    resp[4] = resp[5] = 0  # setez explicit qdcount pe 0    resp[7] = 1 # Ancount 1    for i in range(12, 14 + len(domain_bytes)):        resp[i] = buf[i]    resp[15 + len(domain)] = 1  # QTYPE A    resp[17 + len(domain)] = 1  # QCLASS IN    resp[21 + len(domain)] = 10  # TTL 10 seconds    resp[23 + len(domain)] = 4  # RDLENGTH 4 bytes    ip = load_balancer(client_addr=client_address)    print("ip ", ip)    for i in range(4):        resp[24 + len(domain) + i] = ip[i]    response_bytes = bytes(resp)    print(f"resp {response_bytes}", f"resp len {len(resp)}")    server_socket.sendto(resp, client_address)

bind9 zone

zone "idoc.ro" {    type forward;    //this defines the addresses of the resolvers to which queries fo this zone will be forwarder    forwarders { 54.198.10.101; };    forward only;};

nslookup -debug idoc.ro localhost;; communications error to 127.0.0.1#53: timed outServer: localhostAddress: 127.0.0.1#53


QUESTIONS:idoc.ro, type = A, class = INANSWERS:AUTHORITY RECORDS:ADDITIONAL RECORDS:

** server can't find idoc.ro: SERVFAIL

I expected the BIND9 server to process the requests correctly.


Viewing all articles
Browse latest Browse all 6168

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>