Skip to content

Commit

Permalink
feat: bind demo
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Gianelloni <[email protected]>
  • Loading branch information
wolf31o2 committed May 11, 2023
1 parent 3240f66 commit ac4e24c
Show file tree
Hide file tree
Showing 10 changed files with 106 additions and 2 deletions.
4 changes: 4 additions & 0 deletions bind/named.conf.default-zones
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
zone "." {
type master;
file "/var/lib/bind/root.zone";
};
10 changes: 10 additions & 0 deletions bind/named.conf.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
zone "cardano" {
type master;
file "/var/lib/bind/cardano.zone";
};

// This is just for demo
zone "treehouse.cardano" {
type master;
file "/var/lib/bind/treehouse.zone";
};
13 changes: 13 additions & 0 deletions bind/named.conf.options
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
options {
directory "/var/cache/bind";

recursion yes;
listen-on { any; };
allow-query { any; };
allow-query-cache { none; };

// forwarders {
// 103.196.38.38;
// 103.196.38.39;
// };
};
2 changes: 2 additions & 0 deletions bind/named.root
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
. 60 NS ns1.cardano.
ns1.cardano. 60 A 172.17.0.1
2 changes: 2 additions & 0 deletions bind/root.hints
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
. 86400 IN NS ns1.cardano.
ns1.cardano. 86400 IN A 172.17.0.1
4 changes: 4 additions & 0 deletions bind/root.zone
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
. 86400 IN SOA ns1.cardano. hostmaster.cardano. 1683227483 21600 3600 604800 60
. 86400 IN NS ns1.cardano.
cardano. 86400 IN NS ns1.cardano.
ns1.cardano. 86400 IN A 172.17.0.1
8 changes: 8 additions & 0 deletions bind/treehouse.zone
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
$ORIGIN treehouse.cardano.
$TTL 60
@ IN SOA ns1.treehouse.cardano. hostmaster.treehouse.cardano. 1683773269 21600 3600 604800 60
IN NS ns1.treehouse.cardano.
IN NS ns2.treehouse.cardano.
ns1 IN A 172.17.0.1
ns2 IN A 172.17.0.1
www IN CNAME www.google.com.
8 changes: 7 additions & 1 deletion cardano.zone
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
$ORIGIN cardano.
$TTL 60
@ IN SOA ns.cardano. hostmaster.cardano. (1683227483, 21600, 3600, 604800, 60)
@ IN SOA ns1.cardano. hostmaster.cardano. 1683773269 21600 3600 604800 60
IN NS ns1.cardano.
ns1.cardano. IN A 172.17.0.1
treehouse IN NS ns1.treehouse.cardano.
ns1.treehouse.cardano. IN A 172.17.0.1
treehouse IN NS ns2.treehouse.cardano.
ns2.treehouse.cardano. IN A 172.17.0.1
test IN NS ns1.test.cardano.
ns1.test.cardano. IN A 172.17.0.1
test IN NS ns2.test.cardano.
ns2.test.cardano. IN A 172.17.0.1
52 changes: 52 additions & 0 deletions demo.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env bash

echo Starting BIND server container
docker run -d \
--name bind9-container \
-e TZ=UTC \
-p 30053:53 \
-v $(pwd -P)/bind/named.conf.options:/etc/bind/named.conf.options \
-v $(pwd -P)/bind/named.conf.default-zones:/etc/bind/named.conf.default-zones \
-v $(pwd -P)/bind/named.conf.local:/etc/bind/named.conf.local \
-v $(pwd -P)/bind/root.hints:/usr/share/dns/root.hints \
-v $(pwd -P)/bind/root.zone:/var/lib/bind/root.zone \
-v $(pwd -P)/cardano.zone:/var/lib/bind/cardano.zone \
-v $(pwd -P)/bind/treehouse.zone:/var/lib/bind/treehouse.zone \
ubuntu/bind9:9.18-22.04_beta

sleep 1
__dns=$(docker exec -ti bind9-container ip addr show eth0 | grep inet | awk '{print $2}' | cut -d/ -f1)

echo Looking up . NS records
dig @${__dns} . NS
sleep 1

echo
echo

echo Looking up . A records
dig @${__dns} . A
sleep 1

echo
echo

echo Looking up ns1.cardano A records
dig @${__dns} ns1.cardano A
sleep 1

echo
echo

echo Looking up ns1.treehouse.cardano A records
dig @${__dns} ns1.treehouse.cardano A
sleep 1

echo
echo

echo Looking up www.treehouse.cardano CNAME record
dig @${__dns} www.treehouse.cardano CNAME
sleep 1

docker rm -f bind9-container 2>&1 >/dev/null
5 changes: 4 additions & 1 deletion dns.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def main():

print("$ORIGIN cardano.")
print("$TTL 60")
print("@ IN SOA ns.cardano. hostmaster.cardano. ("+str(now)+", 21600, 3600, 604800, 60)")
print("@ IN SOA ns1.cardano. hostmaster.cardano. "+str(now)+" 21600 3600 604800 60")
print(" IN NS ns1.cardano.")
print("ns1.cardano. IN A 172.17.0.1")

for tx in txs:
name = bytes.fromhex(tx['datum']['json']['fields'][0]['bytes']).decode()
Expand All @@ -35,6 +37,7 @@ def main():
cardano[name] = dict({"origin": origin})
for ns in ns_list:
print(name + " IN NS " + bytes.fromhex(ns['bytes']).decode() + ".")
print(bytes.fromhex(ns['bytes']).decode() + ". IN A 172.17.0.1")

if __name__ == '__main__':
main()
Expand Down

0 comments on commit ac4e24c

Please sign in to comment.