diff --git a/~host-setups/LXC-bootstrap.sh b/~host-setups/LXC-bootstrap.sh index 7ffeed1..951a57e 100644 --- a/~host-setups/LXC-bootstrap.sh +++ b/~host-setups/LXC-bootstrap.sh @@ -4,15 +4,18 @@ apt update && apt upgrade -y #apply all the packages I need apt install -y ca-certificates curl ethtool iptables-persistent git htop -#enable IP forwarding -Enable IP Forwarding (Persistent) +#Enable IP Forwarding (Persistent) sed -i 's/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf grep -qF "net.ipv4.ip_forward=1" /etc/sysctl.conf || echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf sysctl -p -#add the NAT rule for IPtables and save -iptables -C POSTROUTING -t nat -s 172.16.0.0/12 -d 172.16.201.0/24 -j MASQUERADE 2>/dev/null || \ -iptables -t nat -I POSTROUTING 1 -s 172.16.0.0/12 -d 172.16.201.0/24 -j MASQUERADE +# Add the "Catch-All" NAT rule for eth0 +# "If traffic leaves eth0, masquerade it (make it look like the LXC's IP)" +# This works for ANY internal Docker subnet (172.x, 192.x, 10.x) +iptables -C POSTROUTING -t nat -o eth0 -j MASQUERADE 2>/dev/null || \ +iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE + +# Save the rules (Requires iptables-persistent / netfilter-persistent installed) netfilter-persistent save #change the virtio settings and Apply checksum fix immediately