none
Batch File to change MTU values on wireless interfaces RRS feed

  • Question

  • I am trying to make a script to change the MTU for all wireless adapters such as "Wireless Network Connection" with netsh. I could manually set them to just do the default "Wireless Network Connection" however many of them have been renamed. I have attempted to get command line to spit out a list with 

    netsh interface ipv4 show subinterfaces > C:\\Temp\MTU1.txt find /I "Wireless" C:\\Temp\MTU1.txt > C:\\Temp\Wireless.txt

    however when there is extras listed in it, I have looked in to running a powershell get-wmiobject on win32_networkadapters however I cannot find where they are listed as "Wireless Network Connection" some help is needed getting them in the form of a list in a text file so that i can have the command line read it and apply the proper MTU Value.
    Saturday, April 16, 2016 11:31 PM

Answers

  • Create a PS1 file called setmtu.ps1

    $adapt=get-wmiobject win32_networkadapter -Filter 'NetEnabled=True'
    netsh interface ipv4 set subinterface "$($adapt.netconnectionid)"  mtu=1270 store=persistent

    powershell -file c:\temt\setmtu.ps1

    You will have to run this elevated.  A standard user cannot set the MTU.


    \_(ツ)_/


    • Edited by jrv Sunday, April 17, 2016 2:04 AM
    • Marked as answer by Kalamarii_ Sunday, April 17, 2016 2:06 AM
    Sunday, April 17, 2016 2:02 AM
  • powershell -Command " & get-wmiobject win32_networkadapter -Filter "NetEnabled='True'"| select netconnectionid | out-file C:\Temp\MTU.txt"
    for /f "skip=3" %%a in ("C:\Temp\MTU.txt") do set VAR=%%a
    netsh interface ipv4 set subinterface "%VAR%" mtu=1270 store=persistent
    del C:\Temp\MTU.txt
    this is what I ended up coming up with. however now the variable isn't taking correctly.
    • Marked as answer by Kalamarii_ Sunday, April 17, 2016 1:58 AM
    Sunday, April 17, 2016 1:56 AM

All replies

  • The MTU is set by the medium.  For all Ethernet-like connections it is set to 1500.  Straiget Wthernet would likely be set to 1530.  WifI requires 1530 and it is not really setable.

    Why do you think you need to change this?


    \_(ツ)_/

    Sunday, April 17, 2016 12:42 AM
  • This gets the MS Wi-Fi adapter(s):

    gwmi win32_networkadapter -filter 'Name like "%wireless%"'|select *


    \_(ツ)_/


    • Edited by jrv Sunday, April 17, 2016 12:49 AM
    Sunday, April 17, 2016 12:45 AM
  • Here is the MTU as reported by WMI:

    gwmi win32_networkadapter -filter 'Name like "%wireless%"'|
     %{$_.GetRelated('Win32_NetworkAdapterConfiguration')}|
     select MTU

    It will be blank unless the vendor supplies a custom class.  With wireless the radio negotiates the MTU with the router.


    \_(ツ)_/

    Sunday, April 17, 2016 12:53 AM
  • A little checking and the 802.11 maximum MTU is 2304.  On any Broadband it will be reset to 1500 as broadband will be configured as Ethernet over 802.11.  Ethernet on most public networks is MTUd at 1500 for compatibility and to prevent fragmentation.  Most 802.11 routers can set the MTU but all should default to 1500.  If you exceed this it will fragment. If you reduce below you will lose performance.

    Note that 1500 is the industry standard but PPoE is reduced to 1492.

    In older networks,  particularly DSL connections, the MTU was an issue.  All modern networks set MTU automatically or default to the gateway media type.  Wireless gateways use 1500. 


    \_(ツ)_/

    Sunday, April 17, 2016 1:07 AM
  • lowering it for a clients wireless equipment, im just the code monkey who is tasked with makeing the script
    Sunday, April 17, 2016 1:53 AM
  • powershell -Command " & get-wmiobject win32_networkadapter -Filter "NetEnabled='True'"| select netconnectionid | out-file C:\Temp\MTU.txt"
    for /f "skip=3" %%a in ("C:\Temp\MTU.txt") do set VAR=%%a
    netsh interface ipv4 set subinterface "%VAR%" mtu=1270 store=persistent
    del C:\Temp\MTU.txt
    this is what I ended up coming up with. however now the variable isn't taking correctly.
    • Marked as answer by Kalamarii_ Sunday, April 17, 2016 1:58 AM
    Sunday, April 17, 2016 1:56 AM
  • Create a PS1 file called setmtu.ps1

    $adapt=get-wmiobject win32_networkadapter -Filter 'NetEnabled=True'
    netsh interface ipv4 set subinterface "$($adapt.netconnectionid)"  mtu=1270 store=persistent

    powershell -file c:\temt\setmtu.ps1

    You will have to run this elevated.  A standard user cannot set the MTU.


    \_(ツ)_/


    • Edited by jrv Sunday, April 17, 2016 2:04 AM
    • Marked as answer by Kalamarii_ Sunday, April 17, 2016 2:06 AM
    Sunday, April 17, 2016 2:02 AM