From 0ab3fade1bfcb707641ec2804869d1ed6535e1d0 Mon Sep 17 00:00:00 2001 From: juewuy Date: Sun, 2 Aug 2026 10:39:00 +0800 Subject: [PATCH] =?UTF-8?q?~=E4=BC=98=E5=8C=96=E6=96=B0=E6=89=8B=E5=BC=95?= =?UTF-8?q?=E5=AF=BC=E4=B8=AD=E5=90=AF=E7=94=A8IP=E8=BD=AC=E5=8F=91?= =?UTF-8?q?=E7=9A=84=E6=8F=90=E7=A4=BA=E5=8F=8A=E5=AE=9E=E7=8E=B0=E9=80=BB?= =?UTF-8?q?=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- scripts/lang/chs/userguide.lang | 3 ++- scripts/lang/en/userguide.lang | 1 + scripts/menus/userguide.sh | 7 +++++-- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/lang/chs/userguide.lang b/scripts/lang/chs/userguide.lang index 4a8d255d..52a6aad5 100644 --- a/scripts/lang/chs/userguide.lang +++ b/scripts/lang/chs/userguide.lang @@ -6,7 +6,8 @@ UG_OPTION_1="路由设备配置局域网透明代理" UG_OPTION_2="Linux设备仅配置本机代理" UG_OPTION_3="还原之前备份的设置" UG_RESTORE_OK="脚本设置已还原!请重新启动脚本!" -UG_IP_FORWARD_WARN="检测到你的设备尚未开启ip转发,局域网设备将无法正常连接网络,是否立即开启?" +UG_IP_FORWARD_WARN="检测到你的设备尚未开启IP转发,局域网设备将无法正常连接网络,是否立即开启?" +UG_CONTAINER_WARN="注意:容器/虚拟机环境,需要用户手动在宿主机启用IP转发!" UG_ENABLE_LOW_MEM="检测到你的安装目录空间不足10M,是否开启小闪存模式?" UG_IMPORT_CONFIG="这是运行前的最后一步" UG_CONFIG_TIP="你必须拥有一份配置文件才能运行服务!" diff --git a/scripts/lang/en/userguide.lang b/scripts/lang/en/userguide.lang index 26569b02..74a454b0 100644 --- a/scripts/lang/en/userguide.lang +++ b/scripts/lang/en/userguide.lang @@ -7,6 +7,7 @@ UG_OPTION_2="Linux device: local proxy only" UG_OPTION_3="Restore previous backup settings" UG_RESTORE_OK="Script settings have been restored! Please restart the script!" UG_IP_FORWARD_WARN="Your device has not enabled IP forwarding, LAN devices will not connect properly. Enable now?" +UG_CONTAINER_WARN="Notice: In container, IP forwarding must be enabled manually on the host!" UG_ENABLE_LOW_MEM="Your installation directory is less than 10MB, enable low-flash mode?" UG_IMPORT_CONFIG="Import configuration file? (Last step before running)" UG_CONFIG_TIP="You must have a configuration file to run the service!" diff --git a/scripts/menus/userguide.sh b/scripts/menus/userguide.sh index c470d7a8..bb11d4ba 100644 --- a/scripts/menus/userguide.sh +++ b/scripts/menus/userguide.sh @@ -75,10 +75,13 @@ forwhat() { if [ "$(cat /proc/sys/net/ipv4/ip_forward)" = "0" ]; then separator_line "-" content_line "\033[33m$UG_IP_FORWARD_WARN\033[0m" + [ "$systype" = 'container' ] && content_line "\033[31m$UG_CONTAINER_WARN\033[0m" read -r -p "$COMMON_INPUT_R" res [ "$res" = 1 ] && { - echo 'net.ipv4.ip_forward = 1' >>/etc/sysctl.conf - sysctl -w net.ipv4.ip_forward=1 + grep -q '^net\.ipv4\.ip_forward' /etc/sysctl.conf \ + && sed -i 's/^net\.ipv4\.ip_forward.*/net.ipv4.ip_forward = 1/' /etc/sysctl.conf \ + || echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf + sysctl -p /etc/sysctl.conf } fi # 禁止docker启用的net.bridge.bridge-nf-call-iptables