Skip to content

Commit

Permalink
Add host script for ipv4 forward
Browse files Browse the repository at this point in the history
  • Loading branch information
3alpha committed Jan 15, 2025
1 parent 9048436 commit c4f9514
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
26 changes: 26 additions & 0 deletions packages/hostScriptsServices/hostScripts/ensure_ipv4_forward.sh
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion packages/hostScriptsServices/src/hostScripts/runScripts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c4f9514

Please sign in to comment.