diff --git a/build_nat_network.sh b/build_nat_network.sh index bd22a93..612f3d8 100644 --- a/build_nat_network.sh +++ b/build_nat_network.sh @@ -62,6 +62,14 @@ if ! command -v iptables &> /dev/null; then fi iptables -t nat -A POSTROUTING -j MASQUERADE sysctl net.ipv4.ip_forward=1 +if grep -q "^net.ipv4.ip_forward=1" /etc/sysctl.conf; then + if grep -q "^#net.ipv4.ip_forward=1" /etc/sysctl.conf; then + sed -i 's/^#net.ipv4.ip_forward=1/net.ipv4.ip_forward=1/' /etc/sysctl.conf + fi +else + echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf +fi +sysctl -p # 重启配置 service networking restart