Skip to content

Commit

Permalink
Merge pull request #3 from cytopia/release-0.10
Browse files Browse the repository at this point in the history
REL-0.10 Adding injectable custom DNS resolver
  • Loading branch information
cytopia authored May 25, 2017
2 parents b96919f + 7d50aa2 commit 6bb7de0
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ LABEL \
image="bind" \
vendor="cytopia" \
license="MIT" \
build-date="2017-05-10"
build-date="2017-05-24"


###
Expand Down
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Bind Docker

<small>**Latest build:** 2017-05-10</small>
<small>**Latest build:** 2017-05-24</small>

[![Build Status](https://travis-ci.org/cytopia/docker-bind.svg?branch=master)](https://travis-ci.org/cytopia/docker-bind) [![](https://images.microbadger.com/badges/version/cytopia/bind.svg)](https://microbadger.com/images/cytopia/bind "bind") [![](https://images.microbadger.com/badges/image/cytopia/bind.svg)](https://microbadger.com/images/cytopia/bind "bind") [![](https://images.microbadger.com/badges/license/cytopia/bind.svg)](https://microbadger.com/images/cytopia/bind "bind")

Expand Down Expand Up @@ -32,6 +32,7 @@
| DEBUG_COMPOSE_ENTRYPOINT | bool | `0` | Show shell commands executed during start.<br/>Value: `0` or `1` |
| WILDCARD_DOMAIN | string | `` | Specify a wild-card domain to add during startup.<br/>Example: `WILDCARD_DOMAIN=example.com` or `WILDCARD_DOMAIN=local` or `WILDCARD_DOMAIN=loc`<br/>**Note:** `$WILDCARD_ADDRESS` must also be specified. |
| WILDCARD_ADDRESS | string | `` | Specify to which IP address the wild-card domain should point to.<br/>Example: `WILDCARD_ADDRESS=192.168.0.1`<br/>**Note:** $WILDCARD_DOMAIN` must also be specidied. |
| DNS_FORWARDER | string| `` | Specify a comma separated list of IP addresses as custom DNS resolver. This is useful if your LAN already has a DNS server which adds custom/internal domains and you still want to keep them in this DNS server<br/>Example: `DNS_FORWARDER=8.8.8.8,8.8.4.4` |

### Default mount points

Expand Down Expand Up @@ -81,6 +82,21 @@ $ docker run -i \
-t cytopia/bind
```

**4. Add wildcard Domain (TLD) and use your corporate DNS server as resolver**

* `loc` and all its subdomains (such as: `hostname.loc`) will point to `192.168.0.1`:
* Your corporate DNS servers are `10.0.15.1` and `10.0.15.2`

```bash
$ docker run -i \
-p 127.0.0.1:53:53 \
-p 127.0.0.1:53/udp:53/udp \
-e WILDCARD_DOMAIN=loc \
-e WILDCARD_ADDRESS=192.168.0.1 \
-e DNS_FORWARDER=10.0.15.1,10.0.15,2 \
-t cytopia/bind
```

## Version

BIND 9.9.5
49 changes: 49 additions & 0 deletions scripts/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,55 @@ else
fi


###
### Add custom forwarder IP's
###
if ! set | grep '^DNS_FORWARDER=' >/dev/null 2>&1; then
log "warn" "\$DNS_FORWARDER not set."
log "warn" "No custom DNS server will be used as forwarder"
else

# To be pupulated
_forwarders_block=""

# Transform into newline separated forwards:
# x.x.x.x\n
# y.y.y.y\n
_forwards="$( echo "${DNS_FORWARDER}" | sed 's/[[:space:]]*//g' | sed 's/,/\n/g' )"

# loop over them
IFS='
'
for ip in ${_forwards}; do
if ! isip "${ip}"; then
log "err" "DNS_FORWARDER error: not a valid IP address: ${ip}"
exit 1
fi

if [ "${_forwarders_block}" = "" ]; then
_forwarders_block="\t\t${ip};"
else
_forwarders_block="${_forwarders_block}\n\t\t${ip};"
fi
done

if [ "${_forwarders_block}" = "" ]; then
log "err" "DNS_FORWARDER error: variable specified, but no IP addresses found."
exit 1
fi

log "info" "Adding custom DNS forwarder: ${DNS_FORWARDER}"

# forwarders {
# x.x.x.x;
# y.y.y.y;
# };
_forwarders_block="\tforwarders {\n${_forwarders_block}\n\t};"

run "sed -i'' 's/^};$/${_forwarders_block}\n};/' /etc/bind/named.conf.options"
fi



###
### Start
Expand Down

0 comments on commit 6bb7de0

Please sign in to comment.