Last active
January 3, 2026 13:19
-
-
Save alexbaeza/77c27772a194f52bf2421e54a1dd1fc9 to your computer and use it in GitHub Desktop.
linux tailscale0 set MTU
This file contains hidden or 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
| #!/bin/bash | |
| set -e | |
| # ---- Configuration / Arguments ---- | |
| DEFAULT_MTU=1420 # https://github.com/tailscale/tailscale/issues/12393#issuecomment-2893170282 | |
| MTU="${1:-$DEFAULT_MTU}" | |
| # ---- Validation ---- | |
| if ! [[ "$MTU" =~ ^[0-9]+$ ]]; then | |
| echo "Invalid MTU value: '$MTU'. MTU must be a numeric value." | |
| exit 1 | |
| fi | |
| if [ "$(id -u)" -ne 0 ]; then | |
| echo "This script must be run as root. Please use sudo." | |
| exit 1 | |
| fi | |
| UDEV_RULE_PATH="/etc/udev/rules.d/99-tailscale-mtu.rules" | |
| echo "Using MTU value: $MTU" | |
| echo "Creating udev rule file at $UDEV_RULE_PATH..." | |
| cat <<EOF > "$UDEV_RULE_PATH" | |
| ACTION=="add", SUBSYSTEM=="net", KERNEL=="tailscale0", RUN+="/sbin/ip link set dev tailscale0 mtu $MTU" | |
| EOF | |
| echo "Reloading udev rules..." | |
| udevadm control --reload-rules | |
| udevadm trigger --subsystem-match=net --action=add | |
| # Give udev a moment to apply changes | |
| sleep 2 | |
| echo "Verifying MTU for tailscale0 interface..." | |
| ip link show tailscale0 | |
| CURRENT_MTU=$(ip link show tailscale0 | grep -oP 'mtu \K\d+') | |
| if [ "$CURRENT_MTU" -eq "$MTU" ]; then | |
| echo "MTU is correctly set to $MTU for the tailscale0 interface." | |
| else | |
| echo "MTU is not set correctly." | |
| echo "Expected: $MTU" | |
| echo "Actual: $CURRENT_MTU" | |
| exit 1 | |
| fi | |
| echo "Setup complete." |
Author
You aren't by any chance wearing a cape...my hero either way. Thank you.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Download and execute script (one-liner)
curl -fsSL https://gist.githubusercontent.com/alexbaeza/77c27772a194f52bf2421e54a1dd1fc9/raw/b97b1e136bd59ff59daddac0bcf6f24667c6c285/set-mtu.sh | sudo bash