Subversion Repositories ALCASAR

Rev

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

Rev 2831 Rev 2833
Line 1... Line 1...
1
#!/bin/bash
1
#!/bin/bash
2
# $Id: alcasar-dns-local.sh 2831 2020-06-07 21:43:19Z rexy $
2
# $Id: alcasar-dns-local.sh 2833 2020-06-14 10:13:18Z 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 15... Line 15...
15
LOCAL_HOSTNAME_FILE="/etc/hosts"
15
LOCAL_HOSTNAME_FILE="/etc/hosts"
16
 
16
 
17
# define DNS parameters (LAN side)
17
# define DNS parameters (LAN side)
18
INT_DNS_DOMAIN=`grep ^DOMAIN $ALCASAR_CONF_FILE|cut -d"=" -f2`
18
INT_DNS_DOMAIN=`grep ^DOMAIN $ALCASAR_CONF_FILE|cut -d"=" -f2`
19
INT_DNS_HOST=`grep ^HOSTNAME $ALCASAR_CONF_FILE|cut -d"=" -f2`
19
INT_DNS_HOST=`grep ^HOSTNAME $ALCASAR_CONF_FILE|cut -d"=" -f2`
-
 
20
INT_DNS_IP_MASK=`grep ^PRIVATE_IP $ALCASAR_CONF_FILE|cut -d"=" -f2`
20
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`
21
INTIF=`grep ^INTIF $ALCASAR_CONF_FILE|cut -d"=" -f2`
22
INTIF=`grep ^INTIF $ALCASAR_CONF_FILE|cut -d"=" -f2`
22
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`
23
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"
24
 
26
 
25
usage="Usage: alcasar-dns-local.sh {--on | -on} | {--off | -off} | {--add | -add} ip domain | {--del | -del} ip domain | {--reload | -reload}"
27
usage="Usage: alcasar-dns-local.sh {--on | -on} | {--off | -off} | {--add | -add} ip domain | {--del | -del} ip domain | {--reload | -reload}"
26
nb_args=$#
28
nb_args=$#
27
args=$1
29
args=$1
28
if [ $nb_args -eq 0 ]
30
if [ $nb_args -eq 0 ]
Line 36... Line 38...
36
	do
38
	do
37
		systemctl restart $dns
39
		systemctl restart $dns
38
	done
40
	done
39
}
41
}
40
 
42
 
41
function hosts_to_unbound(){
43
function hosts_to_unbound(){  # configure the unbound conf file with local host names resolution (forward + blackhole)
42
		cat << EOF > $LOCAL_DNS_FILE
44
		cat << EOF > $LOCAL_DNS_FILE
43
server:
45
server:
44
	local-zone: "$INT_DNS_DOMAIN" static
46
	local-zone: "$INT_DNS_DOMAIN" static
45
	local-data: "$INT_DNS_HOST.$INT_DNS_DOMAIN A $INT_DNS_IP"
47
	local-data: "$INT_DNS_HOST.$INT_DNS_DOMAIN A $INT_DNS_IP"
46
	local-data-ptr: "$INT_DNS_IP $INT_DNS_HOST.$INT_DNS_DOMAIN"
48
	local-data-ptr: "$INT_DNS_IP $INT_DNS_HOST.$INT_DNS_DOMAIN"
47
EOF
49
EOF
-
 
50
	if [ "$HOSTNAME" != 'alcasar' ]
-
 
51
	then
-
 
52
		echo -e "\tlocal-zone: \"alcasar\" static" >> /etc/unbound/conf.d/common/local-dns/${INTIF}.conf
-
 
53
		echo -e "\tlocal-zone: \"alcasar A $PRIVATE_IP\"" >> /etc/unbound/conf.d/common/local-dns/${INTIF}.conf
-
 
54
		echo -e "\tlocal-zone: \"alcasar\" static" >> /etc/unbound/conf.d/forward/iface.lo.conf
-
 
55
		echo -e "\tlocal-zone: \"alcasar A 127.0.0.1\"" >> /etc/unbound/conf.d/forward/iface.lo.conf
-
 
56
	fi
-
 
57
		cat << EOF > $LOCAL_DNS_BLACKHOLE_FILE
-
 
58
server:
-
 
59
	server:
-
 
60
	interface: ${INT_DNS_IP}@56
-
 
61
	access-control-view: $INT_DNS_IP_MASK $INTIF
-
 
62
view:
-
 
63
	name: "$INTIF"
-
 
64
	local-zone: "." redirect
-
 
65
	local-data: ". A $INT_DNS_IP"
-
 
66
	local-zone: "$INT_DNS_DOMAIN" static
-
 
67
	local-data: "$INT_DNS_HOST.$INT_DNS_DOMAIN A $INT_DNS_IP"
-
 
68
	local-data-ptr: "$INT_DNS_IP $INT_DNS_HOST.$INT_DNS_DOMAIN"
-
 
69
EOF
48
	while read -r line
70
	while read -r line
49
	do
71
	do
50
		ip_address=$(echo $line | awk '{ print $1 }')
72
		ip_address=$(echo $line | awk '{ print $1 }')
51
		domain=$(echo $line | awk '{ print $2 }')
73
		domain=$(echo $line | awk '{ print $2 }')
52
		if ! echo $line | grep -E -q "^([0-9\.\t ]+alcasar( |$)|127\.0\.0)"
74
		if ! echo $line | grep -E -q "^([0-9\.\t ]+alcasar( |$)|127\.0\.0)"
53
		then
75
		then
54
			echo -e "\tlocal-data: \"$domaini.$INT_DNS_DOMAIN A $ip_address\"" >> $LOCAL_DNS_FILE
76
			echo -e "\tlocal-data: \"$domain.$INT_DNS_DOMAIN A $ip_address\"" >> $LOCAL_DNS_FILE
55
			echo -e "\tlocal-data-ptr: \"$ip_address $domain.$INT_DNS_DOMAIN\"" >> $LOCAL_DNS_FILE
77
			echo -e "\tlocal-data-ptr: \"$ip_address $domain.$INT_DNS_DOMAIN\"" >> $LOCAL_DNS_FILE
-
 
78
			echo -e "\tlocal-data: \"$domain.$INT_DNS_DOMAIN A $ip_address\"" >> $LOCAL_DNS_BLACKHOLE_FILE
-
 
79
			echo -e "\tlocal-data-ptr: \"$ip_address $domain.$INT_DNS_DOMAIN\"" >> $LOCAL_DNS_BLACKHOLE_FILE
56
		fi
80
		fi
57
	done < $LOCAL_HOSTNAME_FILE
81
	done < $LOCAL_HOSTNAME_FILE
58
}
82
}
59
 
83
 
60
case $args in
84
case $args in