一些典型的MTU值:
网络: MTU字节
超通道 65535
16Mb/s信息令牌环(IBM) 17914
4Mb/s令牌环(IEEE802.5) 4464
FDDI 4352
以太网 1500
IEEE802.3/802.2 1492
X.25 576
点对点(低时延) 296
路径MTU:如果两台主机之间的通信要通过多个网络,那么每个网络的链路层就可能有不同的MTU。重要的不是两台主机所在网络的MTU的值,重要的是两台通信主机路径中的最小MTU。它被称作路径MTU。
对于不同的PATH 的MTU,需要实现前期的MTU探索算法:
1、把socket设置为ip包不可分片模式 ,这样从client发送一系列不同大小的包到server,超过MTU的包自然会被丢弃。这样可以得到路径MTU值。
2、java 实例
- Enumeration<NetworkInterface> networkInterfaces = NetworkInterface.getNetworkInterfaces();
- int count = 0;
- while (networkInterfaces.hasMoreElements()) {
- NetworkInterface next = networkInterfaces.nextElement();
- System.out.println("getName获取网络设备名称=" + next.getName());
- System.out.println("getDisplayName获得网络设备显示名称=" + next.getDisplayName());
- System.out.println("getMTU获得最大传输单元=" + next.getMTU());
-
- System.out.println("**********************" + count++);
- }
- import java.net.NetworkInterface;
-
- public static int getMaximumTransferUnit() {
- try {
- return NetworkInterface.getByInetAddress(InetAddress.getLocalHost()).getMTU();
- } catch (Throwable throwable) {
- try {
-
- boolean foundDevice = false;
- int lowestMaximumTransferUnit = Integer.MAX_VALUE;
- for (Enumeration<NetworkInterface> networkInterfaces = NetworkInterface
- .getNetworkInterfaces(); networkInterfaces.hasMoreElements(); ) {
- NetworkInterface networkInterface = networkInterfaces.nextElement();
- int maximumTransferUnit = networkInterface.getMTU();
- if (maximumTransferUnit < lowestMaximumTransferUnit
- && maximumTransferUnit >= RakNet.MINIMUM_TRANSFER_UNIT) {
- lowestMaximumTransferUnit = maximumTransferUnit;
- foundDevice = true;
- }
- }
-
- if (foundDevice == false) {
- throw new IOException("Failed to locate a network interface with an MTU higher than the minimum ("
- + RakNet.MINIMUM_TRANSFER_UNIT + ")");
- }
- return lowestMaximumTransferUnit;
- } catch (Throwable throwable2) {
- throwable2.printStackTrace();
- return -1;
- }
- }
- }
-
-
-
-