如何修改 MTU 和巨型帧(Jumbo Frames)设置(Cisco、VMware、Windows、Linux)

Posted by sysin on 2018-08-01
Estimated Reading Time 8 Minutes
Words 1.9k In Total
更新日期:Wed Aug 01 2018 11:10:00 GMT+0800,阅读量:

请访问原文链接:如何修改 MTU 和巨型帧(Jumbo Frames)设置(Cisco、VMware、Windows、Linux),查看最新版。原创作品,转载请保留出处。

作者主页:sysin.org


无耻抄袭者 Yu Tao,请立遁!!!

一、概念

1. MTU 的概念

最大传输单元(Maximum Transmission Unit,MTU)是指一种通信协议在某一层上面所能通过的最大数据报大小(以字节为单位),它通常与链路层协议有密切的关系。

由于以太网传输电气方面的限制,每个以太网帧都有最小的大小 64 bytes,最大不能超过 1518 bytes,对于小于或者大于这个限制的以太网帧,我们都可以视之为错误的数据帧。一般的以太网转发设备会丢弃这些数据帧。(注:小于 64Bytes 的数据帧一般是由于以太网冲突产生的 “碎片” 或者线路干扰或者坏的以太网接口产生的,对于大于 1518 Bytes 的数据帧我们一般把它叫做 Giant 帧,这种一般是由于线路干扰或者坏的以太网口产生)。

由于以太网 EthernetII 最大的数据帧是 1518 Bytes,除去以太网帧的帧头( “DMAC 目的 MAC 地址 48 bit = 6 Bytes” + “SMAC 源 MAC 地址 48 bit = 6 Bytes” + “Type 域 2 Bytes”)14 Bytes 和帧尾 CRC 校验部分 4 Bytes (这个部分有时候大家也把它叫做 FCS),那么剩下承载上层协议的地方也就是 Data 域最大就只能有 1500 Bytes,这个值我们就把它称之为 MTU。

2. 什么是 Jumbo Frames

Jumbo frames 是指比标准 Ethernet Frames 长的 frame,即比 1518/1522bit 大的 frames,Jumbo frame 的大小是每个设备厂商规定的,不属于 IEEE 标准;Jumbo frame 在 full-duplex 的 Ethernet 网络上运行;Jumbo frame 定义了一个 “link negotiation” 协议,来和对端的设备协商,是否对端设备支持使用 Jumbo frames;标准的以太网 IP 报文大小是:1500bit,不包含以太网头和 FCS 的 18bit(6+6+2+4),如果包含以太网头和 FCS,则为 1518bit;Jumbo frame 一般指的是二层封装三层 IP 报文的值大于 9000bit 的报文。

Jumbo frames 的提出背景:在 1998 年,Alteon Networks 公司提出把 Data Link Layer 最大能传输的数据从 1500 bit 增加到 9000 bit,这个提议虽然没有得到 IEEE 802.3 Working Group 的同意,但是大多数设备厂商都已经支持。

3. 使用 Jumbo Frames 的优点

在数据传输时,由于 IEEE 的规定最大的帧规定为 1,500 比特(主机在早期的半双功网络中),所以需要数传输需要经过 “数据的切要 --- 传输 ---数据组合” 的过程。而使用的最大帧越小,传输包的量就越大,计算量相应会多,而产生的后果是:

a:增加主机的计算量,消耗 CPU 资源;

b:影响网络传输的速度。

而使用大帧优点自然也不言而喻 - 降低 CPU 计算量、加快数据传输。

二、如何修改 MTU

1. Cisco 交换机配置

1.1 Catalyst IOS 机型(代表产品:3750/3560/2960)

1
2
3
4
Swtich-SYSIN(config)# system mtu jumbo 9000
Swtich-SYSINconfig)# Changes to the system jumbo MTU will not take effect until the next reload is done
Swtich-SYSIN(config)# exit
Swtich-SYSIN# reload

注意:本例使用 3750X 交换机,测试在同一 vlan 的主机巨型帧通信正常,但在 vlan 之间(不同 vlan)无法通信,原因未知。

1.2 Catalyst IOS XE 机型(代表产品:9000、3850、3650)

9300 switch in our lab:

1
2
3
4
5
6
7
8
9
Swtich-SYSIN#config t
Enter configuration commands, one per line.
End with CNTL/Z.
Swtich-SYSIN(config)#system mtu ? <1500-9198> MTU size in bytes
Swtich-SYSIN(config)#system mtu 9198
Global Ethernet MTU is set to 9198 bytes. Note: this is the Ethernet payload size, not the total Ethernet frame size, which includes the Ethernet header/trailer and possibly other tags, such as ISL or 802.1q tags.
Swtich-SYSIN(config)#^Z
Swtich-SYSIN#show system mtu
Global Ethernet MTU is 9198 bytes.

A reload is not required to change the system MTU. For more details kindly go through the below link.

1.3 Nexus 交换机 NX-OS

MTU 配置介绍

1
2
3
4
5
For Layer 3 interfaces, you can configure an MTU size that is between 576 and 9216 bytes.
对于三层接口,可以配置 MTU 大小为 576 和 9216 字节之间

For Layer 2 interfaces, you can configure all Layer 2 interfaces to use either the default MTU size (1500 bytes) or the system jumbo MTU size (default size of 9216 bytes).
对于第 2 层接口,可以配置所有二层接口,使用默认的 MTU 大小(1500 字节)或系统大型 MTU 大小(9216 字节默认大小)。

配置接口 MTU

1
2
3
4
5
6
7
8
9
10
为三层口配置 MTU:
N7K-SYSIN(config)# interface e4/20
N7K-SYSIN(config-if)# mtu 2346

为二层口配置 MTU:
N7K-SYSIN(config)# interface e3/21
N7K-SYSIN(config-if)# mtu 9216
N7K-SYSIN(config-if)# mtu 1500
N7K-SYSIN(config-if)# mtu 2346
ERROR: Ethernet3/21: MTU on L2 interfaces can only be set to default or system-jumboMTU

修改系统默认 MTU

1
2
3
4
5
6
7
8
9
修改系统默认 MTU:
N7K-SYSIN(config)# system jumbomtu 9000

配置非系统默认 jumbomtu 会产生报错:
N7K-SYSIN(config)# interface e3/21
N7K-SYSIN(config-if)# mtu 9216
^
% Invalid number, range is (1500:9000) at '^' marker.
N7K-SYSIN(config-if)# mtu 9000

配置在交换的虚拟接口 (SVI) 的 MTU

1
2
N7K-SYSIN(config)#interface vlan 1
N7K-SYSIN(config-if)#mtu 9216

2. VMware ESXi 配置

2.1 使用 vSphere Client(Flex 旧版 vSphere Web client 类似)配置

Standard Switch

Home > Hosts and Clusters > Host > Configuration > Networking >:

Virtual Switches > Standard Switch: vSwitch# > Edit > Properties > MTU (Bytes)

VMkernel adapters > vmk# (For example: vmk0) > Edit… > Port properties > MTU

Distributed Switch

Home > Networking > distributed switch (For example: DSwitch1) > ACTIONS > Settings > Edit Settings… > Advanced > MTU (Bytes)

Home > Hosts and Clusters > Host > Configuration > Networking > VMkernel adapters > vmk# (For example: vmk1) > Edit… > Port properties > MTU

2.2 命令行配置

vSwith 配置(Standard Switch 和 Distributed Switch 相同)

1
2
3
4
5
6
7
8
# 查看 vSwitch 信息
esxcfg-vswitch -l

# 配置 MTU (vSwitch:vSwitch0)
esxcfg-vswitch -m 9000 vSwitch0

# 验证配置 (sysin)
esxcfg-vswitch -l

VMkernel 适配器配置

1
2
3
4
5
6
7
8
9
10
# 查看 VMkernel 适配器信息
esxcli network ip interface list
esxcfg-vmknic -l

# 配置 MTU (vmk#:vmk0)
esxcli network ip interface set -m 9000 -i vmk0

# 验证配置 (sysin)
esxcli network ip interface list
esxcfg-vmknic -l

3. 操作系统配置

Windows GUI (Windows Server 2019 为例)

1
控制面板 \ 网络和 Internet \ 网络和共享中心 > Ethenet0 > 属性 (P) > 配置 (C)... > 高级 > Jumbo Packet > 9014

备注:无需重启网卡即可生效,测试在物理机配置后网络短暂中断,虚机配置后网络无中断直接生效。

Windows cmd

1
2
3
4
5
6
查询接口的 MTU 值(验证配置结果同)
netsh interface ipv4 show subinterfaces

设置 MTU
netsh interface ipv4 set subinterface "本地连接" mtu=9014 store=persistent
netsh interface ipv4 set subinterface "Ethernet0" mtu=9014 store=persistent

CentOS / RHEL / Fedora Linux

1
2
3
4
5
6
7
8
vi /etc/sysconfig/network-scripts/ifcfg-eth0
# 增加如下内容
MTU="9000"
# 保存后重启网卡生效
service network restart
nmcli c reload #CentOS8/RHEL8 默认
# 启用 IPv6 地址的,修改 IPv6 mtu 的参数为
IPV6_MTU="1280"

Debian / Ubuntu Linux

1
2
3
4
5
sudo vi /etc/network/interfaces
# 增加如下值
mtu 9000
# 保存后,重启网络生效
/etc/init.d/networking restart

Netplan 配置(Ubuntu 18.04、20.04)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# 18.04:
sudo vim /etc/netplan/50-cloud-init.yaml
# 20.04:
sudo vim /etc/netplan/00-installer-config.yaml
# 格式如下:
network:
ethernets:
eth0:
mtu: 9000
addresses:
- 10.1.10.5/24
gateway4: 10.1.10.1
nameservers:
addresses:
- 10.1.10.11
- 10.1.10.12
search:
- sysin.org
version: 2

4. 测试 Jumbo Frames

To test Jumbo Frames:

  1. Test ping to your neighbor’s virtual machine interface with the command:

    • From Windows:

      1
      2
      3
      4
      ping -f -l 8972 a.b.c.d

      -l size 发送缓冲区大小。
      -f 在数据包中设置 “不分段” 标记 (仅适用于 IPv4)。
    • From Unix:

      1
      ping -s 8972 a.b.c.d
  2. The output appears similar to (sysin):

    1
    2
    PING a.b.c.d (a.b.c.d) 8972(9000) bytes of data.
    8980 bytes from a.b.c.d: icmp_seq=1 ttl=128 time=3.36 ms

To test the network connectivity with Jumbo Frames, from ESX server console/SSH connection to ESX use the command:

1
# vmkping -s 8972 <IPADDRESS of iSCSI SAN>

捐助本站 ❤️ Donate

点击访问官方网站


文章用于推荐和分享优秀的软件产品及其相关技术,所有软件默认提供官方原版(免费版或试用版),免费分享。对于部分产品笔者加入了自己的理解和分析,方便学习和测试使用。任何内容若侵犯了您的版权,请联系作者删除。如果您喜欢这篇文章或者觉得它对您有所帮助,或者发现有不当之处,欢迎您发表评论,也欢迎您分享这个网站,或者赞赏一下作者,谢谢!

支付宝赞赏 微信赞赏

赞赏一下


☑️ 评论恢复,欢迎留言❗️
敬请注册!点击 “登录” - “用户注册”(已知不支持 21.cn/189.cn 邮箱)。请勿使用联合登录(已关闭)