MTU mismatch between netsh and NetworkInterface.GetIPProperties()
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
Related to How to get the current MTU of an interface in C#
But that solution (set both mtu sizes to the same value), doesn't help in my case.
There exists a problem in GetIPv4Properties()
, if the mtu sizes for ipv4 and ipv6 are set differently, then...
If ipv6 is enabled, both (GetIPv4Properties/GetIPv6Properties) return the mtu size of ipv6!
The Mtu value is only correct if the ipv6 protocol is disabled.
using System.Net.NetworkInformation;
foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
{
if (ni.Name == "Local Area Connection")
{
Console.WriteLine(ni.GetIPProperties().GetIPv4Properties().Mtu);
Console.WriteLine(ni.GetIPProperties().GetIPv6Properties().Mtu);
}
}
But the correct values are shown by netsh
netsh interface ipv4 show subinterface "Local Area Connection"
netsh interface ipv6 show subinterface "Local Area Connection"
Without protocol version, the value for ipv4 is shown.
netsh interface ip show subinterface "Local Area Connection"
In my case, I need to check the mtu size for ipv4 independent of the ipv6 protocol enabled or disabled state.
Because my SW only works, if the mtu size is set to 1500 and I want to warn the user otherwise.
Is it possible with the NetworkInterface class or should I use a nasty hack, like
Process process = Process.Start(new ProcessStartInfo("netsh.exe", "interface ipv4 show subinterface "Local Area Connection"") {
UseShellExecute = false,
RedirectStandardOutput = true
});
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
Console.WriteLine(output);
@EDIT:
After the comments from @RonMaupin
There is no difference in MTU for IPv4 or IPv6, which are layer-3
protocols. The MTU is the maximum payload size of the layer-2
protocol, e.g. ethernet
That is correct, but for windows each protocol uses it's own mtu size and fragmentation.
Tested with mtu ipv4=1300 vs ipv6=1500 and ping of 1400 bytes:
netsh interface ipv4 set subinterface "Local Area Connection" mtu=1300 store=persistent
netsh interface ipv6 set subinterface "Local Area Connection" mtu=1500 store=persistent
ping6 -c 5 ff02::1:3 -s 1400
112 28.860467 fe80::64aa:56e9:fb1e:2081 ff02::1:3 ICMPv6 1462 Echo
(ping) request id=0x3160, seq=2, hop limit=1 (multicast)
ping 192.168.101.11 -s 1400
152 102.027390 192.168.101.223 192.168.101.11 IPv4 1314 Fragmented IP
protocol (proto=ICMP 1, off=0, ID=2712)
153 102.027409 192.168.101.223 192.168.101.11 ICMP 162 Echo (ping)
request id=0x3450, seq=0/0, ttl=128 (no response found!)
c# networking mtu
add a comment |
Related to How to get the current MTU of an interface in C#
But that solution (set both mtu sizes to the same value), doesn't help in my case.
There exists a problem in GetIPv4Properties()
, if the mtu sizes for ipv4 and ipv6 are set differently, then...
If ipv6 is enabled, both (GetIPv4Properties/GetIPv6Properties) return the mtu size of ipv6!
The Mtu value is only correct if the ipv6 protocol is disabled.
using System.Net.NetworkInformation;
foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
{
if (ni.Name == "Local Area Connection")
{
Console.WriteLine(ni.GetIPProperties().GetIPv4Properties().Mtu);
Console.WriteLine(ni.GetIPProperties().GetIPv6Properties().Mtu);
}
}
But the correct values are shown by netsh
netsh interface ipv4 show subinterface "Local Area Connection"
netsh interface ipv6 show subinterface "Local Area Connection"
Without protocol version, the value for ipv4 is shown.
netsh interface ip show subinterface "Local Area Connection"
In my case, I need to check the mtu size for ipv4 independent of the ipv6 protocol enabled or disabled state.
Because my SW only works, if the mtu size is set to 1500 and I want to warn the user otherwise.
Is it possible with the NetworkInterface class or should I use a nasty hack, like
Process process = Process.Start(new ProcessStartInfo("netsh.exe", "interface ipv4 show subinterface "Local Area Connection"") {
UseShellExecute = false,
RedirectStandardOutput = true
});
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
Console.WriteLine(output);
@EDIT:
After the comments from @RonMaupin
There is no difference in MTU for IPv4 or IPv6, which are layer-3
protocols. The MTU is the maximum payload size of the layer-2
protocol, e.g. ethernet
That is correct, but for windows each protocol uses it's own mtu size and fragmentation.
Tested with mtu ipv4=1300 vs ipv6=1500 and ping of 1400 bytes:
netsh interface ipv4 set subinterface "Local Area Connection" mtu=1300 store=persistent
netsh interface ipv6 set subinterface "Local Area Connection" mtu=1500 store=persistent
ping6 -c 5 ff02::1:3 -s 1400
112 28.860467 fe80::64aa:56e9:fb1e:2081 ff02::1:3 ICMPv6 1462 Echo
(ping) request id=0x3160, seq=2, hop limit=1 (multicast)
ping 192.168.101.11 -s 1400
152 102.027390 192.168.101.223 192.168.101.11 IPv4 1314 Fragmented IP
protocol (proto=ICMP 1, off=0, ID=2712)
153 102.027409 192.168.101.223 192.168.101.11 ICMP 162 Echo (ping)
request id=0x3450, seq=0/0, ttl=128 (no response found!)
c# networking mtu
There is no difference in MTU for IPv4 or IPv6, which are layer-3 protocols. The MTU is the maximum payload size of the layer-2 protocol, e.g. ethernet.
– Ron Maupin
Nov 22 '18 at 13:20
@RonMaupin, no quite correct in the case of windows. My profinet stack only works reliable when the MTU size of ipv4=1500, but not when ipv4=1300, ipv6=1500
– jeb
Nov 22 '18 at 13:24
The MTU is a layer-2 value (the payload size of the layer-2 frame), and it has nothing to do with the layer-3 protocol used. The layer-3 packet is the payload of the layer-2 frame, and layer-2 does not know or care what layer-3 protocol is carried in the frame. The layer-2 payload size is the layer-2 payload size, regardless of the layer-3 protocol. The layer-3 protocol could even be IPX or AppleTalk, and the layer-2 payload size (MTU) would remain the same because the layer-2 protocol is ignorant of the layer-3 protocol.
– Ron Maupin
Nov 22 '18 at 13:30
add a comment |
Related to How to get the current MTU of an interface in C#
But that solution (set both mtu sizes to the same value), doesn't help in my case.
There exists a problem in GetIPv4Properties()
, if the mtu sizes for ipv4 and ipv6 are set differently, then...
If ipv6 is enabled, both (GetIPv4Properties/GetIPv6Properties) return the mtu size of ipv6!
The Mtu value is only correct if the ipv6 protocol is disabled.
using System.Net.NetworkInformation;
foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
{
if (ni.Name == "Local Area Connection")
{
Console.WriteLine(ni.GetIPProperties().GetIPv4Properties().Mtu);
Console.WriteLine(ni.GetIPProperties().GetIPv6Properties().Mtu);
}
}
But the correct values are shown by netsh
netsh interface ipv4 show subinterface "Local Area Connection"
netsh interface ipv6 show subinterface "Local Area Connection"
Without protocol version, the value for ipv4 is shown.
netsh interface ip show subinterface "Local Area Connection"
In my case, I need to check the mtu size for ipv4 independent of the ipv6 protocol enabled or disabled state.
Because my SW only works, if the mtu size is set to 1500 and I want to warn the user otherwise.
Is it possible with the NetworkInterface class or should I use a nasty hack, like
Process process = Process.Start(new ProcessStartInfo("netsh.exe", "interface ipv4 show subinterface "Local Area Connection"") {
UseShellExecute = false,
RedirectStandardOutput = true
});
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
Console.WriteLine(output);
@EDIT:
After the comments from @RonMaupin
There is no difference in MTU for IPv4 or IPv6, which are layer-3
protocols. The MTU is the maximum payload size of the layer-2
protocol, e.g. ethernet
That is correct, but for windows each protocol uses it's own mtu size and fragmentation.
Tested with mtu ipv4=1300 vs ipv6=1500 and ping of 1400 bytes:
netsh interface ipv4 set subinterface "Local Area Connection" mtu=1300 store=persistent
netsh interface ipv6 set subinterface "Local Area Connection" mtu=1500 store=persistent
ping6 -c 5 ff02::1:3 -s 1400
112 28.860467 fe80::64aa:56e9:fb1e:2081 ff02::1:3 ICMPv6 1462 Echo
(ping) request id=0x3160, seq=2, hop limit=1 (multicast)
ping 192.168.101.11 -s 1400
152 102.027390 192.168.101.223 192.168.101.11 IPv4 1314 Fragmented IP
protocol (proto=ICMP 1, off=0, ID=2712)
153 102.027409 192.168.101.223 192.168.101.11 ICMP 162 Echo (ping)
request id=0x3450, seq=0/0, ttl=128 (no response found!)
c# networking mtu
Related to How to get the current MTU of an interface in C#
But that solution (set both mtu sizes to the same value), doesn't help in my case.
There exists a problem in GetIPv4Properties()
, if the mtu sizes for ipv4 and ipv6 are set differently, then...
If ipv6 is enabled, both (GetIPv4Properties/GetIPv6Properties) return the mtu size of ipv6!
The Mtu value is only correct if the ipv6 protocol is disabled.
using System.Net.NetworkInformation;
foreach (NetworkInterface ni in NetworkInterface.GetAllNetworkInterfaces())
{
if (ni.Name == "Local Area Connection")
{
Console.WriteLine(ni.GetIPProperties().GetIPv4Properties().Mtu);
Console.WriteLine(ni.GetIPProperties().GetIPv6Properties().Mtu);
}
}
But the correct values are shown by netsh
netsh interface ipv4 show subinterface "Local Area Connection"
netsh interface ipv6 show subinterface "Local Area Connection"
Without protocol version, the value for ipv4 is shown.
netsh interface ip show subinterface "Local Area Connection"
In my case, I need to check the mtu size for ipv4 independent of the ipv6 protocol enabled or disabled state.
Because my SW only works, if the mtu size is set to 1500 and I want to warn the user otherwise.
Is it possible with the NetworkInterface class or should I use a nasty hack, like
Process process = Process.Start(new ProcessStartInfo("netsh.exe", "interface ipv4 show subinterface "Local Area Connection"") {
UseShellExecute = false,
RedirectStandardOutput = true
});
string output = process.StandardOutput.ReadToEnd();
process.WaitForExit();
Console.WriteLine(output);
@EDIT:
After the comments from @RonMaupin
There is no difference in MTU for IPv4 or IPv6, which are layer-3
protocols. The MTU is the maximum payload size of the layer-2
protocol, e.g. ethernet
That is correct, but for windows each protocol uses it's own mtu size and fragmentation.
Tested with mtu ipv4=1300 vs ipv6=1500 and ping of 1400 bytes:
netsh interface ipv4 set subinterface "Local Area Connection" mtu=1300 store=persistent
netsh interface ipv6 set subinterface "Local Area Connection" mtu=1500 store=persistent
ping6 -c 5 ff02::1:3 -s 1400
112 28.860467 fe80::64aa:56e9:fb1e:2081 ff02::1:3 ICMPv6 1462 Echo
(ping) request id=0x3160, seq=2, hop limit=1 (multicast)
ping 192.168.101.11 -s 1400
152 102.027390 192.168.101.223 192.168.101.11 IPv4 1314 Fragmented IP
protocol (proto=ICMP 1, off=0, ID=2712)
153 102.027409 192.168.101.223 192.168.101.11 ICMP 162 Echo (ping)
request id=0x3450, seq=0/0, ttl=128 (no response found!)
c# networking mtu
c# networking mtu
edited Nov 22 '18 at 15:08
jeb
asked Nov 22 '18 at 13:16
jebjeb
58.8k13136175
58.8k13136175
There is no difference in MTU for IPv4 or IPv6, which are layer-3 protocols. The MTU is the maximum payload size of the layer-2 protocol, e.g. ethernet.
– Ron Maupin
Nov 22 '18 at 13:20
@RonMaupin, no quite correct in the case of windows. My profinet stack only works reliable when the MTU size of ipv4=1500, but not when ipv4=1300, ipv6=1500
– jeb
Nov 22 '18 at 13:24
The MTU is a layer-2 value (the payload size of the layer-2 frame), and it has nothing to do with the layer-3 protocol used. The layer-3 packet is the payload of the layer-2 frame, and layer-2 does not know or care what layer-3 protocol is carried in the frame. The layer-2 payload size is the layer-2 payload size, regardless of the layer-3 protocol. The layer-3 protocol could even be IPX or AppleTalk, and the layer-2 payload size (MTU) would remain the same because the layer-2 protocol is ignorant of the layer-3 protocol.
– Ron Maupin
Nov 22 '18 at 13:30
add a comment |
There is no difference in MTU for IPv4 or IPv6, which are layer-3 protocols. The MTU is the maximum payload size of the layer-2 protocol, e.g. ethernet.
– Ron Maupin
Nov 22 '18 at 13:20
@RonMaupin, no quite correct in the case of windows. My profinet stack only works reliable when the MTU size of ipv4=1500, but not when ipv4=1300, ipv6=1500
– jeb
Nov 22 '18 at 13:24
The MTU is a layer-2 value (the payload size of the layer-2 frame), and it has nothing to do with the layer-3 protocol used. The layer-3 packet is the payload of the layer-2 frame, and layer-2 does not know or care what layer-3 protocol is carried in the frame. The layer-2 payload size is the layer-2 payload size, regardless of the layer-3 protocol. The layer-3 protocol could even be IPX or AppleTalk, and the layer-2 payload size (MTU) would remain the same because the layer-2 protocol is ignorant of the layer-3 protocol.
– Ron Maupin
Nov 22 '18 at 13:30
There is no difference in MTU for IPv4 or IPv6, which are layer-3 protocols. The MTU is the maximum payload size of the layer-2 protocol, e.g. ethernet.
– Ron Maupin
Nov 22 '18 at 13:20
There is no difference in MTU for IPv4 or IPv6, which are layer-3 protocols. The MTU is the maximum payload size of the layer-2 protocol, e.g. ethernet.
– Ron Maupin
Nov 22 '18 at 13:20
@RonMaupin, no quite correct in the case of windows. My profinet stack only works reliable when the MTU size of ipv4=1500, but not when ipv4=1300, ipv6=1500
– jeb
Nov 22 '18 at 13:24
@RonMaupin, no quite correct in the case of windows. My profinet stack only works reliable when the MTU size of ipv4=1500, but not when ipv4=1300, ipv6=1500
– jeb
Nov 22 '18 at 13:24
The MTU is a layer-2 value (the payload size of the layer-2 frame), and it has nothing to do with the layer-3 protocol used. The layer-3 packet is the payload of the layer-2 frame, and layer-2 does not know or care what layer-3 protocol is carried in the frame. The layer-2 payload size is the layer-2 payload size, regardless of the layer-3 protocol. The layer-3 protocol could even be IPX or AppleTalk, and the layer-2 payload size (MTU) would remain the same because the layer-2 protocol is ignorant of the layer-3 protocol.
– Ron Maupin
Nov 22 '18 at 13:30
The MTU is a layer-2 value (the payload size of the layer-2 frame), and it has nothing to do with the layer-3 protocol used. The layer-3 packet is the payload of the layer-2 frame, and layer-2 does not know or care what layer-3 protocol is carried in the frame. The layer-2 payload size is the layer-2 payload size, regardless of the layer-3 protocol. The layer-3 protocol could even be IPX or AppleTalk, and the layer-2 payload size (MTU) would remain the same because the layer-2 protocol is ignorant of the layer-3 protocol.
– Ron Maupin
Nov 22 '18 at 13:30
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431861%2fmtu-mismatch-between-netsh-and-networkinterface-getipproperties%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53431861%2fmtu-mismatch-between-netsh-and-networkinterface-getipproperties%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
There is no difference in MTU for IPv4 or IPv6, which are layer-3 protocols. The MTU is the maximum payload size of the layer-2 protocol, e.g. ethernet.
– Ron Maupin
Nov 22 '18 at 13:20
@RonMaupin, no quite correct in the case of windows. My profinet stack only works reliable when the MTU size of ipv4=1500, but not when ipv4=1300, ipv6=1500
– jeb
Nov 22 '18 at 13:24
The MTU is a layer-2 value (the payload size of the layer-2 frame), and it has nothing to do with the layer-3 protocol used. The layer-3 packet is the payload of the layer-2 frame, and layer-2 does not know or care what layer-3 protocol is carried in the frame. The layer-2 payload size is the layer-2 payload size, regardless of the layer-3 protocol. The layer-3 protocol could even be IPX or AppleTalk, and the layer-2 payload size (MTU) would remain the same because the layer-2 protocol is ignorant of the layer-3 protocol.
– Ron Maupin
Nov 22 '18 at 13:30