~优化新手引导中启用IP转发的提示及实现逻辑

This commit is contained in:
juewuy
2026-08-02 10:39:00 +08:00
parent c2d9e441d2
commit 0ab3fade1b
3 changed files with 8 additions and 3 deletions
+2 -1
View File
@@ -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="你必须拥有一份配置文件才能运行服务!"
+1
View File
@@ -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!"
+5 -2
View File
@@ -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