@@ -25,6 +25,12 @@ IPV4_GW="10.0.5.1/24"
25
25
IPV6_IP=" fd62:89a2:fda9:e23::3"
26
26
IPV6_GW=" fd62:89a2:fda9:e23::1/64"
27
27
28
+ # Set this to the interface(s) on which you want DNS TCP/UDP port 53 traffic
29
+ # re-routed through this container. Separate interfaces with spaces.
30
+ # This is useful when runinng a DNS service, like Adguard Home
31
+ # e.g. "br0" or "br0 br1" etc.
32
+ FORCED_INTFC=" "
33
+
28
34
# # END OF CONFIGURATION
29
35
30
36
# set VLAN bridge promiscuous
@@ -56,3 +62,23 @@ if ! grep -qxF "interface=br${VLAN}.mac" /run/dnsmasq.conf.d/custom.conf; then
56
62
echo " interface=br${VLAN} .mac" >> /run/dnsmasq.conf.d/custom.conf
57
63
kill -9 " $( cat /run/dnsmasq.pid) "
58
64
fi
65
+
66
+ # (optional) IPv4 force DNS (TCP/UDP 53) through DNS container
67
+ for intfc in ${FORCED_INTFC} ; do
68
+ if [ -d " /sys/class/net/${intfc} " ]; then
69
+ for proto in udp tcp; do
70
+ prerouting_rule=" PREROUTING -i ${intfc} -p ${proto} ! -s ${IPV4_IP} ! -d ${IPV4_IP} --dport 53 -j LOG --log-prefix [DNAT-${intfc} -${proto} ]"
71
+ iptables -t nat -C ${prerouting_rule} 2> /dev/null || iptables -t nat -A ${prerouting_rule}
72
+ prerouting_rule=" PREROUTING -i ${intfc} -p ${proto} ! -s ${IPV4_IP} ! -d ${IPV4_IP} --dport 53 -j DNAT --to ${IPV4_IP} "
73
+ iptables -t nat -C ${prerouting_rule} 2> /dev/null || iptables -t nat -A ${prerouting_rule}
74
+
75
+ # (optional) IPv6 force DNS (TCP/UDP 53) through DNS container
76
+ if [ -n " ${IPV6_IP} " ]; then
77
+ prerouting_rule=" PREROUTING -i ${intfc} -p ${proto} ! -s ${IPV6_IP} ! -d ${IPV6_IP} --dport 53 -j LOG --log-prefix [DNAT-${intfc} -${proto} ]"
78
+ ip6tables -t nat -C ${prerouting_rule} 2> /dev/null || ip6tables -t nat -A ${prerouting_rule}
79
+ prerouting_rule=" PREROUTING -i ${intfc} -p ${proto} ! -s ${IPV6_IP} ! -d ${IPV6_IP} --dport 53 -j DNAT --to ${IPV6_IP} "
80
+ ip6tables -t nat -C ${prerouting_rule} 2> /dev/null || ip6tables -t nat -A ${prerouting_rule}
81
+ fi
82
+ done
83
+ fi
84
+ done
0 commit comments