-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
28 additions
and
1 deletion.
There are no files selected for viewing
26 changes: 26 additions & 0 deletions
26
packages/hostScriptsServices/hostScripts/ensure_ipv4_forward.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters