#!/bin/bash
Case "$" in
-a) shift
If [$#-lt 1]
Then
echo Please input parameter: ' "xxx.cn A 192.168.22.22" '
Else
ifs=$ ' \t\n '
for param in [email protected]
Do
A=
echo ${param%%‘ ‘*}
if test
cat /usr/local/etc/unbound/unbound.conf | grep $a
&>/dev/null
Then
Echo-e "\033[31m Domain $ A has been added before dns-d delete \033[0m"
Exit
Else
Var=
sed -n ‘/local-data:/h;${g;p;}‘ /usr/local/etc/unbound/unbound.conf
Sed-i-E "/$var/a\ local-data: \" "$param" "\" "/usr/local/etc/unbound/unbound.conf
ifs=$ ' \t\n '
Fi
Done
If unbound-checkconf &>/dev/null
Then
Systemctl Restart Unbound.service
Else
echo Please re-check the domain name format
echo format: \ "domain A ip\"
x=
cat /usr/local/etc/unbound/unbound.conf | grep "$1"| cut -d: -f2
Echo-e "\033[31m $x \033[0m"
ECHO-E "\033[31m error domain name can be deleted using dns-d" $x "and then add \033[0m using dns-a command"
Fi
fi;;
-d) Shift
If [$#-lt 1]
Then
echo Please input parameter: ' "qq.cn A 192.168.22.22" '
Else
ifs=$ ' \t\n '
for param in [email protected]
Do
Sed-i-E "/\" "" $param "" \ "/d"/usr/local/etc/unbound/unbound.conf
ifs=$ ' \t\n '
Done
If unbound-checkconf &>/dev/null
Then
Systemctl Restart Unbound.service
Else
echo Please re-check the domain name format
echo format: \ "domain A ip\"
x=
cat /usr/local/etc/unbound/unbound.conf | grep "$1"| cut -d: -f2
Echo-e "\033[31m $x \033[0m"
ECHO-E "\033[31m error domain name can be deleted using dns-d" $x "and then add \033[0m using dns-a command"
Fi
fi;;
-m) if [$#-ne 3]
Then
echo First enter the domain name resolution space to be modified and enter the modified domain name resolution
echo Please input parameters: ' "qq.cn a 192.168.22.22" "" "qq.cn a 192.168.55.55" '
Else
I=
cat /usr/local/etc/unbound/unbound.conf | grep "$2"| cut -d: -f1
if [$i = = "Local-data"]
Then
Sed-i "s/^.
"" $ "" .$/local-data: \ "" "$ $" "\"/g "/usr/local/etc/unbound/unbound.conf
Else
echo "does not have this domain name resolution, if you want to add please use the-a option directly"
Exit
Fi
If unbound-checkconf &>/dev/null
Then
Systemctl Restart Unbound.service
Else
echo Please re-check the domain name format
echo format: \ "domain A ip\"
x=
cat /usr/local/etc/unbound/unbound.conf | grep "$3"| cut -d: -f2
Echo-e "\033[31m $x \033[0m"
ECHO-E "\033[31m error domain name can be deleted using dns-d" $x "and then add \033[0m using dns-a command"
Fi
fi;;
*) echo "is not a valid option"
echo "-A adds a DNS resolution record"
echo "-D delete a DNS resolution record"
echo "-m modifies a DNS parsing record";;
Esac
The error display is optimized to display the wrong domain name directly. Add domain name when added to determine whether the domain name has been added.
-M is still a bit of a bug when it is not found, the syntax error does not affect the use of
Copy the above shell script directly to the local to modify the location of the unbound.conf according to the way you installed it.
Save
vi/root/dns.sh
chmod u+x/root/dns.sh
Ln/root/dns.sh/usr/bin/dns
Add Dns-a
Delete dns-d
Modify Dns-m
Unbound DNS installation Control shell script