diff --git a/packages/hostScriptsServices/hostScripts/ensure_ipv4_forward.sh b/packages/hostScriptsServices/hostScripts/ensure_ipv4_forward.sh new file mode 100644 index 000000000..9e3f992c8 --- /dev/null +++ b/packages/hostScriptsServices/hostScripts/ensure_ipv4_forward.sh @@ -0,0 +1,26 @@ +#!/bin/bash +# ensure_ipv4_forward.sh +# This script ensures that IPv4 forwarding is enabled on the system. + +set -e +set -o pipefail + + +# Check if IPv4 forwarding is already enabled. +if sysctl net.ipv4.ip_forward | grep -q 'net.ipv4.ip_forward = 1'; then + echo "IPv4 forwarding is already enabled." + exit 0 +fi + +# If the configuration is already present in /etc/sysctl.conf or /etc/sysctl.d/, do not change it. +if grep -Eq '^[^#]*net\.ipv4\.ip_forward\s*=' /etc/sysctl.conf /etc/sysctl.d/* 2>/dev/null; then + echo "Found existing IPv4 forwarding configuration. Exiting." + exit 0 +fi + +# Enable IPv4 forwarding. +dest_file="/etc/sysctl.conf" +[ -d /etc/sysctl.d ] && dest_file="/etc/sysctl.d/99-tailscale.conf" + +echo 'net.ipv4.ip_forward = 1' | tee -a $dest_file +sysctl -p $dest_file \ No newline at end of file diff --git a/packages/hostScriptsServices/src/hostScripts/runScripts.ts b/packages/hostScriptsServices/src/hostScripts/runScripts.ts index 65fdf92f7..8327dffc4 100644 --- a/packages/hostScriptsServices/src/hostScripts/runScripts.ts +++ b/packages/hostScriptsServices/src/hostScripts/runScripts.ts @@ -17,7 +17,8 @@ type ScriptName = | "avahi_daemon.sh" | "reboot_required.sh" | "docker_upgrade.sh" - | "update_upgrade.sh"; + | "update_upgrade.sh" + | "ensure_ipv4_forward.sh"; /** * Run a script for the hostScripts folder