Post

Install Bind9 in Docker

deployement bind docker container as dns server

Install Bind9 in Docker

Prerequisites

  • install docker
  • install docker-compose

Edit the config file of systemd-resolved, /etc/systemd/resolved.conf.

Uncomment the line DNSStubListener, and set it to no.

1
2
3
4
[Resolve]
...
DNSStubListener=no
...

Restart the sytemd-resolved service using sudo systemctl restart systemd-resolved.

Create Docker-Compose file

Copy the example docker-compose.yml file in your project directory, and make sure you replace the container_name value with your desired container name.

Example docker-compose.yml:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
version: "3"

services:
  bind9:
    container_name: dns-demo-1
    image: ubuntu/bind9:latest
    environment:
      - BIND9_USER=root
      - TZ=Etc/UTC
    ports:
      - "53:53/tcp"
      - "53:53/udp"
    volumes:
      - ./config:/etc/bind
      - ./cache:/var/cache/bind
      - ./records:/var/lib/bind
    restart: unless-stopped

Create the main config file

Copy the example named.conf file in the ./config/ folder of your project directory, and make sure you replace the values, with your desired configuration.

Example named.conf:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
acl internal {
  192.168.10.0/24;
};

options {
  forwarders {
    1.1.1.1;
    1.0.0.1;
  };
  allow-query { internal; };
};

zone "demo.ahmedbouayed.tn" IN {
  type master;
  file "/etc/bind/demo-ahmedbouayed-tn.zone";
};

Prepare the zone file

Copy the example demo-ahmedbouayed-tn.zone file in the ./config/ folder of your project directory, and make sure you replace the values, with your desired configuration.

Example demo-ahmedbouayed-tn.zone:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
$TTL 2d

$ORIGIN demo.ahmedbouayed.tn.

@             IN     SOA    ns.ahmedbouayed.tn. info.ahmedbouayed.tn (
                            2022121900     ; serial
                            12h            ; refresh
                            15m            ; retry
                            3w             ; expire
                            2h )           ; minimum TTL

              IN     NS     ns.demo.ahmedbouayed.tn.

ns            IN     A      192.168.10.118

srv-demo-1    IN     A      192.168.10.118
*.srv-demo-1  IN     A      192.168.10.118

Add your DNS Records

According to the following examples, you can add additional DNS Records, defined in the IANA’s DNS Resource Records TYPEs.

Start the container

To start the container, execute the following command in the project directory.

1
docker-compose up -d
This post is licensed under CC BY 4.0 by the author.

Trending Tags