Last active
November 12, 2024 00:53
-
-
Save chrismooredev/27ee3780a9e2a27b8f8f9134855bbb62 to your computer and use it in GitHub Desktop.
Script to set WSL eth0 MTU to the same as a (lower) Pulse Secure Juniper Networks adapter 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 | |
| # Sets the WSL eth0 adapter to the same MTU as a Juniper Networks Virtual Adapter, from the Windows side. | |
| # This can help make certain connections (SSH/HTTPS specifically) more stable/reliable, as they can use | |
| # larger packets when initiating connections or sending large chunks of data. | |
| # Recommended to run in ~/.profile to persist across reboots. Remember to make this script executable. | |
| # Add to sudoers file if running in ~/.profile | |
| # %sudo ALL=(ALL) NOPASSWD: /usr/sbin/ip link set mtu * dev * | |
| win_adapter_description="Juniper Networks Virtual Adapter" | |
| wsl_adapter_name="eth0" | |
| wsl_adapter_mtu="$(ip link show dev "$wsl_adapter_name" | grep -oP 'mtu \d+' | cut -d' ' -f2)" | |
| win_adapter_name="$(ipconfig.exe /all | grep -B3 "$win_adapter_description" | head -n1 | cut -d' ' -f3- | cut -d':' -f1)" | |
| if [ -z "$win_adapter_name" ] ; then | |
| exit | |
| fi | |
| win_adapter_mtu="$(netsh.exe interface ipv4 show interfaces | grep "$win_adapter_name" | tr -s ' ' | cut -d' ' -f4)" | |
| if [ $UID -eq 0 ] ; then | |
| use_sudo= | |
| else | |
| use_sudo=sudo | |
| fi | |
| $use_sudo /usr/sbin/ip link set mtu "$win_adapter_mtu" dev "$wsl_adapter_name" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment