Skip to content

Instantly share code, notes, and snippets.

@ziozzang
Last active January 28, 2019 23:42
Show Gist options
  • Save ziozzang/285e6b35d933e8208b34f3a42688ae97 to your computer and use it in GitHub Desktop.
Save ziozzang/285e6b35d933e8208b34f3a42688ae97 to your computer and use it in GitHub Desktop.
DNS server with whitelist/blacklist.

TL;DR

  • DNSP is very simple and useful tool to setup whitelisted or blacklisted dns proxy server.
  • if you want to use with dockered image, this script will be a good starting point.

Author

# Code by Jioh L. Jung <ziozzang@gmail.com>
# Original Code from https://github.com/gophergala/dnsp
#- Temporary Directory to build DNSP
DNSP_DIR=`mktemp -d -t dnsp.XXXXXX`
#- Build binary with Newest Golang
docker run --rm \
-v ${DNSP_DIR}:/go/bin/ -v ${DNSP_DIR}:/usr/src/dnsp/ \
-w /usr/src/dnsp/ \
-e "CGO_ENABLED=0" -e "GOOS=linux" \
--net=host \
--entrypoint=/bin/bash \
golang -c \
"go get -u github.com/gophergala/dnsp/... && true"
#- Copy Binary and Remove temporary directory.
cp -f "${DNSP_DIR}/dnsp" ./
rm -rf "${DNSP_DIR}"
#- Generate dockerfile to build
cat > dockerfile << EOF
FROM scratch
COPY ./dnsp /dnsp
entrypoint ["/dnsp"]
EOF
#- Build as docker images
docker build -t dnsp .
  • Generate whitelist file
cat > dnsp.whitelist << EOF
*.wikipedia.org
*.wikimedia.org
wikipedia.org
wikimedia.org
EOF
  • Run as DNSP with docker.
# 1.1.1.1 is upstream dns server to resolve
# add '-t 0.0.0.0:8080' as option, to start webUI.
docker run \
  -d --name=dnsp \
  --restart=always \
  -v `pwd`:/data \
  --net=host \
  dnsp -r 1.1.1.1 --whitelist=/data/dnsp.whitelist

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