Skip to content

Commit

Permalink
qzeleza#213 *_dns_routing: переправление в loopback
Browse files Browse the repository at this point in the history
  • Loading branch information
AltGrF13 authored and AltGrF13 committed Nov 18, 2024
1 parent 84eb7a1 commit 57c2957
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions opt/etc/ndm/ndm
Original file line number Diff line number Diff line change
Expand Up @@ -284,16 +284,15 @@ ip4_add_to_dns_routing() {
local submessage=''
fi

local router_ip=$(get_router_ip)
for protocol in tcp udp ; do
if ip4save | grep -F 'PREROUTING' | grep -F -- "${iptables_filter}" | grep -F "${protocol}" | grep -F 53 | grep -F 'DNAT' | grep -F "${router_ip}" | grep -Fq "${DNS_PORT}" ; then
if ip4save | grep -F 'PREROUTING' | grep -F -- "${iptables_filter}" | grep -F "${protocol}" | grep -F 53 | grep -F 'DNAT' | grep -F '127.0.0.1' | grep -Fq "${DNS_PORT}" ; then
continue
fi

log_warning "Подключение перенаправления ${protocol} в DNSMasq${submessage}"

# без echo дублирование пробелов (что даёт warning и проблему наличия)
iptables -A PREROUTING -w -t nat$(echo "${iptables_filter}") -p "${protocol}" --dport 53 -j DNAT --to-destination "${router_ip}":"${DNS_PORT}"
iptables -A PREROUTING -w -t nat$(echo "${iptables_filter}") -p "${protocol}" --dport 53 -j DNAT --to-destination 127.0.0.1:"${DNS_PORT}"
done
}

Expand Down Expand Up @@ -723,16 +722,15 @@ ip4_delete_from_dns_routing() {
local submessage=''
fi

local router_ip=$(get_router_ip)
for protocol in tcp udp ; do
if ! ip4save | grep -F 'PREROUTING' | grep -F -- "${iptables_filter}" | grep -F "${protocol}" | grep -F 53 | grep -F 'DNAT' | grep -F "${router_ip}" | grep -Fq "${DNS_PORT}" ; then
if ! ip4save | grep -F 'PREROUTING' | grep -F -- "${iptables_filter}" | grep -F "${protocol}" | grep -F 53 | grep -F 'DNAT' | grep -F '127.0.0.1' | grep -Fq "${DNS_PORT}" ; then
continue
fi

log_warning "Отключение перенаправления ${protocol} в DNSMasq${submessage}"

# без echo дублирование пробелов (что даёт warning и проблему наличия)
iptables -D PREROUTING -w -t nat$(echo "${iptables_filter}") -p "${protocol}" --dport 53 -j DNAT --to-destination "${router_ip}":"${DNS_PORT}"
iptables -D PREROUTING -w -t nat$(echo "${iptables_filter}") -p "${protocol}" --dport 53 -j DNAT --to-destination 127.0.0.1:"${DNS_PORT}"
done
}

Expand Down

0 comments on commit 57c2957

Please sign in to comment.