【Network】MTU(Maximum Transmission Unit)最佳设置

Posted by 西维蜀黍 on 2021-05-04, Last Modified on 2023-09-27

MTU (Maximum Transmission Unit)

In computer networking, the maximum transmission unit (MTU) is the size of the largest protocol data unit (PDU) that can be communicated in a single network layer transaction. The MTU relates to, but is not identical to the maximum frame size that can be transported on the data link layer, e.g. Ethernet frame.

Larger MTU is associated with reduced overhead. Smaller MTU values can reduce network delay. In many cases, MTU is dependent on underlying network capabilities and must be adjusted manually or automatically so as to not exceed these capabilities. MTU parameters may appear in association with a communications interface or standard. Some systems may decide MTU at connect time.

Tradeoffs

A larger MTU brings greater efficiency because each network packet carries more user data while protocol overheads, such as headers or underlying per-packet delays, remain fixed; the resulting higher efficiency means an improvement in bulk protocol throughput.

A larger MTU also requires processing of fewer packets for the same amount of data. This generally results in a faster and more efficient transmission of data across your network.

However, this gain is not without a downside. Large packets occupy a slow link for more time than a smaller packet, causing greater delays to subsequent packets, and increasing network delay and delay variation. For example, a 1500-byte packet, the largest allowed by Ethernet at the network layer, ties up a 14.4k modem for about one second.

Large packets are also problematic in the presence of communications errors. If no forward error correction is used, corruption of a single bit in a packet requires that the entire packet be retransmitted, which can be costly. At a given bit error rate, larger packets are more susceptible to corruption. Their greater payload makes retransmissions of larger packets take longer. Despite the negative effects on retransmission duration, large packets can still have a net positive effect on end-to-end TCP performance.

MTUs for common media

Media for IP transport Maximum transmission unit (bytes) Notes
Internet IPv4 path MTU At least 68,[5] max of 64 KiB[6] Systems may use Path MTU Discovery[7] to find the actual path MTU. Routing from larger MTU to smaller MTU causes IP fragmentation.
Internet IPv6 path MTU At least 1280,[8] max of 64 KiB, but up to 4 GiB with optional jumbogram[9] Systems must use Path MTU Discovery[10] to find the actual path MTU.
Ethernet v2 1500[11] Nearly all IP over Ethernet implementations use the Ethernet II frame format.
Ethernet with LLC and SNAP 1492[12]
Ethernet jumbo frames 1501 – 9202[13] or more[14] The limit varies by vendor. For correct interoperation, frames should be no larger than the maximum frame size supported by any device on the network segment.[15] Jumbo frames are usually only seen in special-purpose networks.
PPPoE v2 1492[16] Ethernet II MTU (1500) less PPPoE header (8)
DS-Lite over PPPoE 1452 Ethernet II MTU (1500) less PPPoE header (8) and IPv6 header (40)
PPPoE jumbo frames 1493 – 9190 or more[17] Ethernet Jumbo Frame MTU (1501 - 9198) less PPPoE header (8)
IEEE 802.11 Wi-Fi (WLAN) 2304[18] The maximum MSDU size is 2304 before encryption. WEP will add 8 bytes, WPA-TKIP 20 bytes, and WPA2-CCMP 16 bytes.
Token Ring (802.5) 4464
FDDI 4352[7]

Jumbo frame

In computer networking, jumbo frames are Ethernet frames with more than 1500 bytes of payload, the limit set by the IEEE 802.3 standard.

Commonly, jumbo frames can carry up to 9000 bytes of payload, but smaller and larger variations exist and some care must be taken using the term. Many Gigabit Ethernet switches and Gigabit Ethernet network interface controllers can support jumbo frames. Some Fast Ethernet switches and Fast Ethernet network interface cards can also support jumbo frames.

Experiment

Step 1

先发一个 ICMP 包 body 长度为1 byte 的进行测试:

$ sudo ping  192.168.18.33 -s 1

  • 这个 ICMP 包的 frame 长度为 43 bytes
    • Header: 14 bytes
    • Body (是一个 IPV4 Packet)
      • Header: 20 bytes
      • Body (是一个 ICMP Packet)
        • Header: 8 bytes
        • Body: 1 byte

此时,MTU 设置为9000。

Step 2

$ sudo ping  192.168.18.33 -s 9000

两个 Ethernet II Frame

  • Frame 1 - 9010 bytes
    • Header: 14 bytes
    • Body (是一个IPV4 Packet) - 8996 bytes
      • Header: 20 bytes
      • Body (是一个 ICMP Packet 的一部分),8976 bytes
  • Frame 2 - 66 bytes
    • Header: 14 bytes
    • Body (是一个IPV4 Packet) - 52 bytes
      • Header: 20 bytes
      • Body (是一个 ICMP Packet 的一部分),32 bytes

这个 ICMP Packet 总共 9000 bytes

  • Header: 8 bytes
  • Body: 8992 bytes

可以观察到,这个ICMP 实际上被 fragmented 成了两个 IPV4 Packet

Ref

How to Modify MTU

Ubuntu

non-persistent

$ ip link set mtu 1200 eth0

# or
$ ifconfig eth0 mtu 9000

Ref

persistent - dynamic IP

Edit the nano /etc/dhcp/dhclient.conf using the following command:

$ sudo nano /etc/dhcp/dhclient.conf

Then add the following lines below the “send host-name = gethostname(); line:

default interface-mtu <mtu_size>;
supersede interface-mtu <mtu_size>;

For instance, to set the MTU size to 1400, we will add:

interface "interface_name" {
default interface-mtu <mtu_size>;
supersede interface-mtu <mtu_size>;

persistent - static IP

*$* sudo nano /etc/network/interfaces

Append the below line in the file:

post-up /sbin/ifconfig <interface-name> mtu <mtu_size>

Make sure to replace with the actual interface name and <mtu_size> with the MTU size you want to set on the network interface.

For instance, to change the MTU size of an interface named ens33 to 1300 bytes, the command would be:

post-up /sbin/ifconfig ens33 mtu 1300 up

Reference