Skip to content

Commit

Permalink
Added support for multiple upstream DNS servers (#25)
Browse files Browse the repository at this point in the history
  • Loading branch information
satishweb authored Dec 19, 2024
1 parent 05e5b81 commit dac3771
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 108 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.alpine
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ USER nobody
# Set environment defaults
# We are using OpenDNS DNS server address as default
# Here is the list of addresses: https://use.opendns.com/
ENV UPSTREAM_DNS_SERVER="udp:208.67.222.222:53"
ENV UPSTREAM_DNS_SERVER="udp:208.67.222.222:53,udp:208.67.220.220:53"
ENV DOH_HTTP_PREFIX="/getnsrecord"
ENV DOH_SERVER_LISTEN=":8053"
ENV DOH_SERVER_TIMEOUT="10"
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile.ubuntu
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ USER nobody
# Set environment defaults
# We are using OpenDNS DNS server address as default
# Here is the list of addresses: https://use.opendns.com/
ENV UPSTREAM_DNS_SERVER="udp:208.67.222.222:53"
ENV UPSTREAM_DNS_SERVER="udp:208.67.222.222:53,udp:208.67.220.220:53"
ENV DOH_HTTP_PREFIX="/getnsrecord"
ENV DOH_SERVER_LISTEN=":8053"
ENV DOH_SERVER_TIMEOUT="10"
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ test-all:
$(L)${MAKE} run-tests IMAGE=${IMAGE_TEST} TAGNAME=${TAGNAME}

run-tests:
$(L)cd tests; pipenv install --python 3.10
$(L)cd tests; pipenv install --python 3.12
$(L)cd tests; pipenv run python ./test-doh-server.py --image ${IMAGE}:${TAGNAME}-alpine

# Commands:
Expand Down
12 changes: 12 additions & 0 deletions docker-entrypoint
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,18 @@ do
printf "| ENTRYPOINT: Exporting var: $varName\n"
done

# If UPSTREAM_DNS_SERVER contains a comma (i.e., multiple servers are provided)
if [[ "$UPSTREAM_DNS_SERVER" == *","* ]]; then
# Convert the comma-separated list into a valid array for the config file
upstream_servers=$(echo "$UPSTREAM_DNS_SERVER" | sed 's/,/","/g')
upstream_servers="[\"$upstream_servers\"]"
else
# If only a single DNS server is provided, use it as before
upstream_servers="[\"$UPSTREAM_DNS_SERVER\"]"
fi

export upstream_servers

# lets generate config file by replacing all variables inside of it.
TMP_FILE=/tmp/doh-server.conf
cp ${DOH_CONFIG_SAMPLE_FILE} ${TMP_FILE}
Expand Down
2 changes: 1 addition & 1 deletion doh-server.sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ path = "${DOH_HTTP_PREFIX}"
# "udp:8.8.8.8:53",
# "udp:8.8.4.4:53",
# ]
upstream = [ "${UPSTREAM_DNS_SERVER}" ]
upstream = ${upstream_servers}

# Upstream timeout
# timeout = 10
Expand Down
2 changes: 1 addition & 1 deletion tests/Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ requests = "*"
[dev-packages]

[requires]
python_version = "3.10"
python_version = "3.12"
221 changes: 118 additions & 103 deletions tests/Pipfile.lock

Large diffs are not rendered by default.

0 comments on commit dac3771

Please sign in to comment.