如何设置网口的MTU?
时间:2019-11-20 08:53:32 来源:igfitidea点击:
MTU(最大传输单元)是协议中一次传输的数据报文的最大大小。
可以在Linux下使用ifconfig命令查看当前的MTU设置:
/sbin/ifconfig
输出:
eth0 Link encap:Ethernet HWaddr 00:0F:EA:91:04:07 inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0 inet6 addr: fe80::20f:eaff:fe91:407/64 Scope:Link UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1 RX packets:141567 errors:0 dropped:0 overruns:0 frame:0 TX packets:141306 errors:0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:1000 RX bytes:101087512 (96.4 MiB) TX bytes:32695783 (31.1 MiB) Interrupt:18 Base address:0xc000
或者使用ip命令:
$ ip link list
输出示例:
1: lo: mtu 16436 qdisc noqueue link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: eth0: mtu 1500 qdisc pfifo_fast qlen 1000 link/ether 00:0f:ea:91:04:07 brd ff:ff:ff:ff:ff:ff 3: sit0: mtu 1480 qdisc noop link/sit 0.0.0.0 brd 0.0.0.0
可以看到,eth0的MTU设置为1500。
假设要将其设置为1200,则可以使用下面的命令来设置MTU:
# ifconfig eth0 mtu 1200
或者
# ip link set dev eth0 mtu 1200
使用以下命令验证是否已设置新的mtu:
$ ip link list
永久设置MTU
要为eth0永久设置MTU,编辑配置文件:
/etc/network/interfaces(Debian Linux):
auto lo iface lo inet loopback auto eth0 iface eth0 inet static name Ethernet LAN card address 192.168.1.2 netmask 255.255.255.0 broadcast 192.168.1.255 network 192.168.1.0 gateway 192.168.1.254 mtu 1200 post-up /etc/fw.start post-down /etc/fw.stop
/etc/sysconfig/network-scripts/ifcfg-eth0(Red Hat Linux)
DEVICE=eth0 BOOTPROTO=static BROADCAST=192.168.1.255 HWADDR=00:0F:EA:91:04:07 IPADDR=192.168.1.111 NETMASK=255.255.255.0 NETWORK=192.168.1.0 MTU=1200 ONBOOT=yes TYPE=Ethernet
保存文件并重启网络服务
Debian:
# /etc/init.d/networking restart
Redhat:
# service network restart