From 90aeeb0fd5f0d033e085bf4bc2a117239b75cce7 Mon Sep 17 00:00:00 2001 From: spiritLHLS <103393591+spiritLHLS@users.noreply.github.com> Date: Mon, 10 Apr 2023 14:40:44 +0800 Subject: [PATCH] Update build_nat_network.sh --- build_nat_network.sh | 8 ++++++++ 1 file changed, 8 insertions(+) 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