Skip to content

Instantly share code, notes, and snippets.

Last active March 5, 2023 07:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
Create BIND9 on Docker Container


I once had a case of bypassing the default DNS from the institution, because there were lots of important website blocks. But we are also not allowed to use a public DNS resolver like etc., if we use a public DNS our internet will be immediately disconnected. Therefore, here I will create a bastion container that uses the default gateway to a VPS and installs BIND9 as the DNS Forwarder.


  • Docker
  • OVPN or any VPN client profile
  • 1 Interface for Bridge to Router


  • VM with Ubuntu Server for Host Container
  • VM with 2 Interface, ens3 for default link & ens12 for bridge BIND9 link
  • Default gateway on
  • DNS IP will be who will forward to &
  • Please adjust for your needs.

Create Dockerfile

FROM ubuntu:20.04
RUN apt update && \
apt install openvpn curl -y
COPY client.ovpn /etc/openvvpn
ENTRYPOINT [ "openvpn", "--config", "/etc/openvpn/client.ovpn" ]
docker build -t bind9 .

Install Package Inside Container

docker build -t bind9 .
docker network create -d ipvlan \
--subnet \
--gateway \
-o parent=ens12 \
docker run -d --restart always --network forBind9 --ip --name bind9 --cap-add NET_ADMIN --device=/dev/net/tun bind9
apt-get update
apt-get install bind9 bind9utils bind9-doc


nc -vz 53
nc -vzu 53

Try on your linux or anything :
nano /etc/resolv.conf


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment