Subversion Repositories ALCASAR

Rev

Rev 2838 | Rev 2947 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log

Rev 2838 Rev 2861
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
# $Id: alcasar-dns-local.sh 2838 2020-06-21 22:15:26Z rexy $
2
# $Id: alcasar-dns-local.sh 2861 2020-10-04 20:41:06Z rexy $
3
 
3
 
4
# alcasar-dns-local.sh
4
# alcasar-dns-local.sh
5
# by Rexy - 3abtux
5
# by Rexy - 3abtux
6
# This script is distributed under the Gnu General Public License (GPL)
6
# This script is distributed under the Gnu General Public License (GPL)
7
 
7
 
Line 20... Line 20...
20
INT_DNS_IP_MASK=`grep ^PRIVATE_IP $ALCASAR_CONF_FILE|cut -d"=" -f2`
20
INT_DNS_IP_MASK=`grep ^PRIVATE_IP $ALCASAR_CONF_FILE|cut -d"=" -f2`
21
INT_DNS_IP=`grep ^PRIVATE_IP $ALCASAR_CONF_FILE|cut -d"=" -f2|cut -d"/" -f1`
21
INT_DNS_IP=`grep ^PRIVATE_IP $ALCASAR_CONF_FILE|cut -d"=" -f2|cut -d"/" -f1`
22
INTIF=`grep ^INTIF $ALCASAR_CONF_FILE|cut -d"=" -f2`
22
INTIF=`grep ^INTIF $ALCASAR_CONF_FILE|cut -d"=" -f2`
23
INT_DNS_ACTIVE=`grep INT_DNS_ACTIVE $ALCASAR_CONF_FILE|cut -d"=" -f2`
23
INT_DNS_ACTIVE=`grep INT_DNS_ACTIVE $ALCASAR_CONF_FILE|cut -d"=" -f2`
24
LOCAL_DNS_FILE="/etc/unbound/conf.d/common/local-dns/$INTIF.conf"
24
LOCAL_DNS_FILE="/etc/unbound/conf.d/common/local-dns/$INTIF.conf"
25
LOCAL_DNS_BLACKHOLE_FILE="/etc/unbound/conf.d/blackhole/iface.$INTIF.conf"
-
 
26
 
25
 
27
usage="Usage: alcasar-dns-local.sh {--on | -on} | {--off | -off} | {--add | -add} ip domain | {--del | -del} ip domain | {--reload | -reload}"
26
usage="Usage: alcasar-dns-local.sh {--on | -on} | {--off | -off} | {--add | -add} ip domain | {--del | -del} ip domain | {--reload | -reload}"
28
nb_args=$#
27
nb_args=$#
29
args=$1
28
args=$1
30
if [ $nb_args -eq 0 ]
29
if [ $nb_args -eq 0 ]
Line 38... Line 37...
38
	do
37
	do
39
		systemctl restart $dns
38
		systemctl restart $dns
40
	done
39
	done
41
}
40
}
42
 
41
 
43
function hosts_to_unbound(){  # configure the unbound conf file with local host names resolution (forward + blackhole)
42
function hosts_to_unbound(){  # configure the unbound conf file with local host names resolution
44
		cat << EOF > $LOCAL_DNS_FILE
43
		cat << EOF > $LOCAL_DNS_FILE
45
server:
44
server:
46
	local-zone: "$INT_DNS_DOMAIN" static
-
 
47
	local-data: "$INT_DNS_HOST.$INT_DNS_DOMAIN A $INT_DNS_IP"
-
 
48
	local-data-ptr: "$INT_DNS_IP $INT_DNS_HOST.$INT_DNS_DOMAIN"
-
 
49
EOF
-
 
50
		cat << EOF > $LOCAL_DNS_BLACKHOLE_FILE
-
 
51
server:
-
 
52
	server:
-
 
53
	interface: ${INT_DNS_IP}@56
-
 
54
	access-control-view: $INT_DNS_IP_MASK $INTIF
-
 
55
view:
-
 
56
	name: "$INTIF"
-
 
57
	local-zone: "." redirect
-
 
58
	local-data: ". A $INT_DNS_IP"
-
 
59
	local-zone: "$INT_DNS_DOMAIN" static
-
 
60
	local-data: "$INT_DNS_HOST.$INT_DNS_DOMAIN A $INT_DNS_IP"
45
	local-data: "$INT_DNS_HOST.$INT_DNS_DOMAIN A $INT_DNS_IP"
61
	local-data-ptr: "$INT_DNS_IP $INT_DNS_HOST.$INT_DNS_DOMAIN"
46
	local-data-ptr: "$INT_DNS_IP $INT_DNS_HOST.$INT_DNS_DOMAIN"
62
EOF
47
EOF
63
	while read -r line
48
	while read -r line
64
	do
49
	do
Line 66... Line 51...
66
		domain=$(echo $line | awk '{ print $2 }')
51
		domain=$(echo $line | awk '{ print $2 }')
67
		if ! echo $line | grep -E -q "^([0-9\.\t ]+alcasar( |$)|127\.0\.0)"
52
		if ! echo $line | grep -E -q "^([0-9\.\t ]+alcasar( |$)|127\.0\.0)"
68
		then
53
		then
69
			echo -e "\tlocal-data: \"$domain.$INT_DNS_DOMAIN A $ip_address\"" >> $LOCAL_DNS_FILE
54
			echo -e "\tlocal-data: \"$domain.$INT_DNS_DOMAIN A $ip_address\"" >> $LOCAL_DNS_FILE
70
			echo -e "\tlocal-data-ptr: \"$ip_address $domain.$INT_DNS_DOMAIN\"" >> $LOCAL_DNS_FILE
55
			echo -e "\tlocal-data-ptr: \"$ip_address $domain.$INT_DNS_DOMAIN\"" >> $LOCAL_DNS_FILE
71
			echo -e "\tlocal-data: \"$domain.$INT_DNS_DOMAIN A $ip_address\"" >> $LOCAL_DNS_BLACKHOLE_FILE
-
 
72
			echo -e "\tlocal-data-ptr: \"$ip_address $domain.$INT_DNS_DOMAIN\"" >> $LOCAL_DNS_BLACKHOLE_FILE
-
 
73
		fi
56
		fi
74
	done < $LOCAL_HOSTNAME_FILE
57
	done < $LOCAL_HOSTNAME_FILE
75
}
58
}
76
 
59
 
77
case $args in
60
case $args in