File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 22set -euo pipefail # Exit on error, undefined vars, and pipeline failures
33IFS=$' \n\t ' # Stricter word splitting
44
5+ # 1. Extract Docker DNS info BEFORE any flushing
6+ DOCKER_DNS_RULES=$( iptables-save -t nat | grep " 127\.0\.0\.11" || true)
7+
58# Flush existing rules and delete existing ipsets
69iptables -F
710iptables -X
@@ -11,6 +14,16 @@ iptables -t mangle -F
1114iptables -t mangle -X
1215ipset destroy allowed-domains 2> /dev/null || true
1316
17+ # 2. Selectively restore ONLY internal Docker DNS resolution
18+ if [ -n " $DOCKER_DNS_RULES " ]; then
19+ echo " Restoring Docker DNS rules..."
20+ iptables -t nat -N DOCKER_OUTPUT 2> /dev/null || true
21+ iptables -t nat -N DOCKER_POSTROUTING 2> /dev/null || true
22+ echo " $DOCKER_DNS_RULES " | xargs -L 1 iptables -t nat
23+ else
24+ echo " No Docker DNS rules to restore"
25+ fi
26+
1427# First allow DNS and localhost before any restrictions
1528# Allow outbound DNS
1629iptables -A OUTPUT -p udp --dport 53 -j ACCEPT
You can’t perform that action at this time.
0 commit comments