dnsmasq: add dns redirect option

This commit is contained in:
Lienol 2020-06-21 22:13:28 +08:00 committed by CN_SZTL
parent ae5c339f80
commit fe76bf3564
No known key found for this signature in database
GPG Key ID: 6850B6345C862176
3 changed files with 24 additions and 4 deletions

View File

@ -32,10 +32,6 @@ sed -i "s/# //g" /etc/opkg/distfeeds.conf
sed -i 's/root::0:0:99999:7:::/root:$1$V4UetPzk$CYXluq4wUazHjmCDBCqXF.:0:0:99999:7:::/g' /etc/shadow
sed -i 's|root:x:0:0:root:/root:/bin/ash|root:x:0:0:root:/root:/bin/bash|g' /etc/passwd
sed -i '/REDIRECT --to-ports 53/d' /etc/firewall.user
echo "iptables -t nat -A PREROUTING -p udp --dport 53 -j REDIRECT --to-ports 53" >> /etc/firewall.user
echo "iptables -t nat -A PREROUTING -p tcp --dport 53 -j REDIRECT --to-ports 53" >> /etc/firewall.user
sed -i '/option disabled/d' /etc/config/wireless
sed -i '/set wireless.radio${devidx}.disabled/d' /lib/wifi/mac80211.sh
wifi up

View File

@ -21,6 +21,7 @@ config dnsmasq
#list bogusnxdomain '64.94.110.11'
option localservice 1 # disable to allow DNS requests from non-local subnets
option filter_aaaa 0
option dns_redirect 1
config dhcp lan
option interface lan

View File

@ -1084,6 +1084,10 @@ dnsmasq_start()
procd_add_jail_mount_rw /var/run/dnsmasq/ $leasefile
procd_close_instance
config_get_bool dns_redirect "$cfg" dns_redirect 0
config_get dns_port "$cfg" port 53
[ "$dns_redirect" = 1 ] && iptables -t nat -A PREROUTING -m comment --comment "DNSMASQ" -p udp --dport 53 -j REDIRECT --to-ports $dns_port
}
dnsmasq_stop()
@ -1101,6 +1105,23 @@ dnsmasq_stop()
rm -f ${BASEDHCPSTAMPFILE}.${cfg}.*.dhcp
}
iptables_clear()
{
nums=$(iptables -t nat -n -L PREROUTING 2>/dev/null | grep -c "DNSMASQ")
if [ -n "$nums" ]; then
until [ "$nums" = 0 ]
do
rules=$(iptables -t nat -n -L PREROUTING --line-num 2>/dev/null | grep "DNSMASQ" | awk '{print $1}')
for rule in $rules
do
iptables -t nat -D PREROUTING $rule 2> /dev/null
break
done
nums=$(expr $nums - 1)
done
fi
}
add_interface_trigger()
{
local interface ignore
@ -1153,6 +1174,7 @@ start_service() {
}
reload_service() {
iptables_clear
rc_procd start_service "$@"
procd_send_signal dnsmasq "$@"
}
@ -1179,4 +1201,5 @@ stop_service() {
else
config_foreach dnsmasq_stop dnsmasq
fi
iptables_clear
}