Initial commit, see README.md for details

This commit is contained in:
Lockszmith (cs-dbg@VAST) 2025-04-26 01:26:21 +03:00
commit aeb96a02a7
10 changed files with 184 additions and 0 deletions

34
README.md Normal file
View File

@ -0,0 +1,34 @@
# Docker DNS Lab
```mermaid
flowchart TD
client["client<br/>172.20.0.100"]
subgraph main["example.com"]
maindns[(maindns<br/>ns1.example.com<br/>172.20.0.10)]
subgraph sub["sub.example.com"]
subdns[(subdns<br/>ns1.sub.example.com<br/>172.20.0.20)]
end
end
client -->|"DNS"| maindns
maindns -->|"delegate:sub"| subdns
```
## Running
```shell
#start the containers
./start-dnslab.sh
# do your tests
./dnslab dig ns1.example.com
./dnslab dig ns1.sub.example.com
./dnslab ip -br a
```
## Cleaning up
```
./cleanup-dnslab.sh
```

8
cleanup-dnslab.sh Executable file
View File

@ -0,0 +1,8 @@
#! /usr/bin/env bash
set -e
docker compose down --remove-orphans
[[ $# -eq 0 ]] || docker run --rm -v .:/tmp/x bash -vc "cd /tmp/x; ${*:-ls -la --color}"

5
client_Dockerfile Normal file
View File

@ -0,0 +1,5 @@
FROM ubuntu
RUN apt-get update \
&& apt-get install --yes dnsutils iputils-arping iputils-ping iproute2

56
compose.yaml Normal file
View File

@ -0,0 +1,56 @@
services:
maindns:
image: internetsystemsconsortium/bind9:9.18
container_name: maindns
command: -u root -g -d 9 -f -c /etc/bind/named.conf
volumes:
- maindns_etc_bind:/etc/bind
- ./maindns_named.conf:/etc/bind/named.conf:ro
- ./db.example.com:/etc/bind/db.example.com:ro
tmpfs:
- /var/cache/bind
- /var/log
depends_on:
- subdns
networks:
dnsnet:
ipv4_address: 172.20.0.10
subdns:
image: internetsystemsconsortium/bind9:9.18
command: -u root -g -d 9 -f -c /etc/bind/named.conf
container_name: subdns
volumes:
- subdns_etc_bind:/etc/bind
- ./subdns_named.conf:/etc/bind/named.conf:ro
- ./db.sub.example.com:/etc/bind/db.sub.example.com:ro
tmpfs:
- /var/cache/bind
- /var/log
networks:
dnsnet:
ipv4_address: 172.20.0.20
client:
build:
dockerfile: client_Dockerfile
container_name: client
command: sleep infinity
depends_on:
- maindns
dns:
- 172.20.0.10
networks:
dnsnet:
ipv4_address: 172.20.0.100
networks:
dnsnet:
driver: bridge
ipam:
config:
- subnet: 172.20.0.0/24
volumes:
maindns_etc_bind:
subdns_etc_bind:

13
db.example.com Normal file
View File

@ -0,0 +1,13 @@
$TTL 86400
@ IN SOA ns1.example.com. admin.example.com. (
1 ; Serial
3600 ; Refresh
1800 ; Retry
604800 ; Expire
86400 ) ; Minimum TTL
IN NS ns1.example.com.
ns1 IN A 172.20.0.10
; Delegate subdomain to subdns
sub IN NS ns1.sub.example.com.
ns1.sub IN A 172.20.0.20

10
db.sub.example.com Normal file
View File

@ -0,0 +1,10 @@
$TTL 86400
@ IN SOA ns1.sub.example.com. admin.sub.example.com. (
1 ; Serial
3600 ; Refresh
1800 ; Retry
604800 ; Expire
86400 ) ; Minimum TTL
IN NS ns1.sub.example.com.
ns1 IN A 172.20.0.20
client IN A 172.20.0.100

6
dnslab Executable file
View File

@ -0,0 +1,6 @@
#! /usr/bin/env bash
set -e
docker exec -it client "${@:-bash}"

24
maindns_named.conf Normal file
View File

@ -0,0 +1,24 @@
options {
directory "/var/cache/bind";
listen-on port 53 { any; };
allow-query { any; };
recursion no;
};
zone "example.com" {
type master;
file "/etc/bind/db.example.com";
};
zone "sub.example.com" {
type delegation-only;
};
logging {
channel default_log {
file "/var/log/named.log";
severity info;
print-time yes;
};
category default { default_log; };
};

8
start-dnslab.sh Executable file
View File

@ -0,0 +1,8 @@
#! /usr/bin/env bash
set -e
docker compose down --remove-orphans \
&& docker compose build \
&& docker compose up -d

20
subdns_named.conf Normal file
View File

@ -0,0 +1,20 @@
options {
directory "/var/cache/bind";
listen-on port 53 { any; };
allow-query { any; };
recursion no;
};
zone "sub.example.com" {
type master;
file "/etc/bind/db.sub.example.com";
};
logging {
channel default_log {
file "/var/log/named.log";
severity info;
print-time yes;
};
category default { default_log; };
};