fix MWP hole punch for production use. bind to 0.0.0.0 instead of
published IP, resend packets every 500ms instead of single-shot, fix Docker iptables-legacy chains so miniupnpd port mapping fully works without warnings
This commit is contained in:
@@ -32,13 +32,29 @@ echo "External interface: $EXTERNAL_IF ($EXTERNAL_IP)"
|
||||
|
||||
# Set up NAT (masquerade internal traffic going out external interface)
|
||||
echo "Setting up NAT..."
|
||||
iptables -t nat -A POSTROUTING -o $EXTERNAL_IF -j MASQUERADE
|
||||
iptables -A FORWARD -i $INTERNAL_IF -o $EXTERNAL_IF -j ACCEPT
|
||||
iptables -A FORWARD -i $EXTERNAL_IF -o $INTERNAL_IF -m state --state RELATED,ESTABLISHED -j ACCEPT
|
||||
# miniupnpd uses libiptc (legacy iptables API), so all rules must use iptables-legacy
|
||||
iptables-legacy -t nat -A POSTROUTING -o $EXTERNAL_IF -j MASQUERADE
|
||||
iptables-legacy -A FORWARD -i $INTERNAL_IF -o $EXTERNAL_IF -j ACCEPT
|
||||
iptables-legacy -A FORWARD -i $EXTERNAL_IF -o $INTERNAL_IF -m state --state RELATED,ESTABLISHED -j ACCEPT
|
||||
|
||||
# Create MINIUPNPD chains that miniupnpd needs for port mapping
|
||||
# PREROUTING: DNAT rules to redirect external ports to internal clients
|
||||
iptables-legacy -t nat -N MINIUPNPD
|
||||
iptables-legacy -t nat -A PREROUTING -j MINIUPNPD
|
||||
# POSTROUTING: masquerade rules for hairpin NAT (internal-to-internal via external IP)
|
||||
iptables-legacy -t nat -N MINIUPNPD-POSTROUTING
|
||||
iptables-legacy -t nat -A POSTROUTING -j MINIUPNPD-POSTROUTING
|
||||
# FORWARD: filter rules for forwarded traffic
|
||||
iptables-legacy -N MINIUPNPD
|
||||
iptables-legacy -A FORWARD -j MINIUPNPD
|
||||
|
||||
# Create miniupnpd config with UPnP ENABLED and NAT-PMP DISABLED
|
||||
# This forces peers to use UPnP IGD (SSDP + SOAP) instead of NAT-PMP
|
||||
FAKE_PUBLIC_IP="93.184.216.34" # example.com IP - just needs to look public
|
||||
# miniupnpd rejects private IPs for ext_ip, so we use a public-looking IP
|
||||
# and add it as an alias on the external interface so it's actually routable
|
||||
FAKE_PUBLIC_IP="93.184.216.34"
|
||||
ip addr add $FAKE_PUBLIC_IP/32 dev $EXTERNAL_IF
|
||||
echo "Added $FAKE_PUBLIC_IP as alias on $EXTERNAL_IF"
|
||||
cat > /tmp/miniupnpd.conf << EOF
|
||||
ext_ifname=$EXTERNAL_IF
|
||||
ext_ip=$FAKE_PUBLIC_IP
|
||||
|
||||
Reference in New Issue
Block a user