From 1a8f2a47fd40281159a25768a75eaf1b9c2f59ef Mon Sep 17 00:00:00 2001 From: Kirill Ziuzin Date: Fri, 6 Apr 2018 00:11:42 +0300 Subject: [PATCH] ud-02 Add support for DNS servers - Add dns configuration file - Add DNS logic - Update readme --- README.md | 3 +++ dns.conf | 4 ++++ unblocker.sh | 48 +++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 48 insertions(+), 7 deletions(-) create mode 100644 dns.conf diff --git a/README.md b/README.md index e0ffbe2..06130b4 100644 --- a/README.md +++ b/README.md @@ -41,3 +41,6 @@ Add list of domains into `domains.conf` ./unblocker.sh ``` +## Optional + +You can add you own DNS server - just add it into `dns.conf`. diff --git a/dns.conf b/dns.conf new file mode 100644 index 0000000..047a587 --- /dev/null +++ b/dns.conf @@ -0,0 +1,4 @@ +1.1.1.1 +8.8.8.8 +8.8.4.4 +77.88.8.8 diff --git a/unblocker.sh b/unblocker.sh index 75656d7..074ee36 100755 --- a/unblocker.sh +++ b/unblocker.sh @@ -1,11 +1,19 @@ #!/bin/sh -## Intial settings +####################################### +## Intial settings ## +####################################### + SCRIPT_DIR=`pwd` CONFIG_PATH="$SCRIPT_DIR/settings.conf" DOMAINS_PATH="$SCRIPT_DIR/domains.conf" +DNS_PATH="$SCRIPT_DIR/dns.conf" + +####################################### +## Check and read configuration file ## +####################################### -## Check and read configuration file +## Settings file if [ ! -f "$CONFIG_PATH" ]; then echo "Configuration file is not exist!" >&2 exit 1 @@ -25,12 +33,38 @@ if [ ! -f "$DOMAINS_PATH" ]; then exit 1 fi -## Add Google DNS into route table -route add 8.8.8.8/32 dev $TUN; -route add 8.8.4.4/32 dev $TUN; -route add 77.88.8.8/32 dev $TUN; +## Check DNS configuration file +if [ ! -f "$DNS_PATH" ]; then + echo "DNS file is not exist" >&2 + exit 1 +fi + +####################################### +## Process dns ## +####################################### + +while read -r DNS +do + echo "Start to process DNS [$DNS]..." >&2 + + ## Check on exist route to DNS + DNS_EXIST="$(ip route get "$DNS" | awk 'NR==1{print $3}')" + + if [ "$DNS_EXIST" == "$TUN" ]; then + echo "Route for DNS [$DNS] already exist" >&2 + else + echo " * Adding route for DNS [$DNS]" >&2 + route add "$DNS" dev "$TUN" + fi + + echo "End of process DNS [$DNS]" >&2 + echo "" >&2 +done < "$DNS_PATH" + +####################################### +## Process domains ## +####################################### -## Process domains while read -r DOMAIN do echo "Start to process domain [$DOMAIN]..." >&2