Skip to content

Instantly share code, notes, and snippets.

@livelace
Created January 17, 2019 13:08
Show Gist options
  • Save livelace/c03b5549e075c637e1e2537cfc579f14 to your computer and use it in GitHub Desktop.
Save livelace/c03b5549e075c637e1e2537cfc579f14 to your computer and use it in GitHub Desktop.
Different ways to set MTU at startup Windows based operating system.
@ECHO OFF
chcp 65001
SET FLAG="C:\testlab-common\tmp\MTU.flag"
SET MTU=1450
ECHO "INFO: Make directory for MTU flag."
mkdir "C:\testlab-common\tmp" 2> nul
wmic os get Caption | find "Windows XP" > nul
SET "XP_STATUS=%ERRORLEVEL%"
ECHO "INFO: Detect Openstack by Neutron router address"
ipconfig /all | find "10.21.0.1" > nul
SET "OPENSTACK_STATUS=%ERRORLEVEL%"
IF "%XP_STATUS%" == "0" (
ECHO "INFO: Windows XP detected. "
IF "%OPENSTACK_STATUS%" == "0" (
ECHO "INFO: Openstack environment was detected, set MTU throw Windows Registry."
IF EXIST %FLAG% (
ECHO "INFO: MTU already set!"
) ELSE (
FOR /F %%I IN ('wmic NicConfig WHERE IPEnabled^=TRUE GET settingid ^| find "{"') DO (
reg add HKLM\SYSTEM\CurrentControlSet\Services\tcpip\parameters\interfaces\%%~I /v MTU /t REG_DWORD /d "%MTU%" /f
)
ECHO True > "%FLAG%"
shutdown -r -f -t 10 2> nul
)
) ELSE (
ECHO "INFO: Openstack environment wasn't detected. Skip MTU settings."
del /F "%FLAG%" 2> nul
)
) ELSE (
ECHO "INFO: Set MTU with help of netsh."
FOR /F "skip=3 tokens=4* " %%A IN ('netsh interface show interface') DO (
netsh interface ipv4 set interface interface="%%A %%B" mtu="%MTU%" store="active" > nul
netsh interface ipv4 set interface interface="%%A %%B" mtu="%MTU%" store="persistent" > nul
)
ECHO True > "%FLAG%"
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment