@@ -485,25 +485,33 @@ enable_ip_forwarding() {
485485 local setting
486486
487487 if [[ " $os " == " Linux" ]]; then
488- config_file=" /etc/sysctl.conf"
488+ config_file=" /etc/sysctl.d/99-erebrus. conf"
489489 setting=" net.ipv4.ip_forward=1"
490490
491- # Check if setting exists exactly
492- if grep -qE " ^${setting} $" " $config_file " ; then
493- log_info " IP forwarding is already enabled in $config_file "
494- else
495- # Remove old or conflicting settings
491+ log_info " Configuring IP forwarding in $config_file "
492+
493+ # Remove any conflicting settings from the target file if it exists
494+ if [[ -f " $config_file " ]]; then
496495 sudo sed -i ' /^net\.ipv4\.ip_forward/d' " $config_file "
497- # Add the correct setting
498- echo " $setting " | sudo tee -a " $config_file " > /dev/null
499- log_info " IP forwarding added to $config_file "
500496 fi
501497
502- log_info " Applying sysctl settings..."
503- if sudo sysctl -p | grep -q " $setting " ; then
504- log_success " sysctl applied successfully, IP forwarding is enabled"
498+ # Add the correct setting
499+ echo " $setting " | sudo tee " $config_file " > /dev/null
500+ log_info " IP forwarding setting written to $config_file "
501+
502+ # Apply all sysctl settings from all config files
503+ log_info " Applying sysctl settings using sysctl --system..."
504+ if sudo sysctl --system >> " $LOG_FILE " 2>&1 ; then
505+ # Verify the setting actually took effect
506+ if [[ " $( sysctl -n net.ipv4.ip_forward) " == " 1" ]]; then
507+ log_success " IP forwarding is enabled and verified"
508+ return 0
509+ else
510+ log_error " sysctl applied, but IP forwarding not active"
511+ return 1
512+ fi
505513 else
506- log_error " Failed to apply sysctl settings"
514+ log_error " Failed to apply sysctl settings with sysctl --system "
507515 return 1
508516 fi
509517
0 commit comments