ubuntu:network:change_the_mtu_of_a_network_interface
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revision | |||
ubuntu:network:change_the_mtu_of_a_network_interface [2020/07/15 09:30] – external edit 127.0.0.1 | ubuntu:network:change_the_mtu_of_a_network_interface [2021/01/07 11:15] (current) – removed peter | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | ====== Ubuntu - Network - Change the MTU of a network interface ====== | ||
- | |||
- | To change the MTU of a network interface | ||
- | |||
- | |||
- | ===== Background ===== | ||
- | |||
- | The maximum transmission unit (MTU) of a network interface is the size of the largest block of data that can be transmitted as a single unit. Anything larger than the MTU must be broken into smaller units prior to transmission. | ||
- | |||
- | MTUs can be measured either at the network layer or at the link layer. | ||
- | |||
- | A common reason for wanting to increase the MTU of an interface is to improve the throughput of high-speed Ethernet. | ||
- | |||
- | Possible reasons for wanting to reduce the MTU include: | ||
- | |||
- | * matching the MTU to that of another network (in order to avoid fragmentation when carrying UDP, and to streamline PMTU discovery when carrying TCP); | ||
- | * matching the MTU to a whole number of ATM cells (when you know that the traffic will at some point need to be encoded using AAL5); or | ||
- | * improving throughput on lines with very high error rates. | ||
- | |||
- | MTUs should not normally be mixed on any given Internet Protocol subnet, however it is possible (and common) for subnets with different MTUs to be connected to each other by means of a router. | ||
- | |||
- | ---- | ||
- | |||
- | ===== Non-persistent Method ===== | ||
- | |||
- | The MTU of an interface can be changed temporarily using the mtu option of the ifconfig command: | ||
- | |||
- | <code bash> | ||
- | ifconfig eth0 mtu 9000 | ||
- | </ | ||
- | |||
- | The new MTU will not persist beyond a reboot. | ||
- | |||
- | ---- | ||
- | |||
- | ===== Persistent Method ===== | ||
- | |||
- | If the interface has (or can be given) a static configuration in **/ | ||
- | |||
- | <file bash / | ||
- | auto eth0 | ||
- | iface eth0 inet static | ||
- | address 192.168.0.2 | ||
- | netmask 255.255.255.0 | ||
- | mtu 9000 | ||
- | </ | ||
- | |||
- | **NOTE**: | ||
- | |||
- | You can activate the new MTU can by taking the interface down using **ifdown** then bringing it back up using **ifup**: | ||
- | |||
- | <code bash> | ||
- | ifdown eth0 | ||
- | ifup eth0 | ||
- | </ | ||
- | |||
- | Alternatively you could reboot the machine. | ||
- | |||
- | See: | ||
- | |||
- | * [[http:// | ||
- | * [[http:// | ||
- | |||
- | ---- | ||
- | |||
- | ===== Testing ===== | ||
- | |||
- | ==== Check the configured MTU ==== | ||
- | |||
- | You can verify that an interface has the intended MTU using the **-i** option of the **netstat** command: | ||
- | |||
- | <code bash> | ||
- | netstat -i | ||
- | </ | ||
- | |||
- | The MTU of each interface is listed in the second column of the output: | ||
- | |||
- | <code bash> | ||
- | Iface MTU Met RX-OK RX-ERR RX-DRP RX-OVR | ||
- | eth0 1500 0 9658 0 0 0 308 0 0 0 BMRU | ||
- | lo 16436 0 | ||
- | Alternatively you can obtain essentially the same information using the ifconfig command: | ||
- | |||
- | ifconfig eth0 | ||
- | The MTU is then listed after the interface address (or addresses) but before the packet counters: | ||
- | |||
- | eth0 Link encap: | ||
- | inet addr: | ||
- | UP BROADCAST RUNNING MULTICAST | ||
- | RX packets: | ||
- | TX packets:309 errors:0 dropped:0 overruns:0 carrier:0 | ||
- | collisions: | ||
- | RX bytes: | ||
- | </ | ||
- | |||
- | Remember that the value listed is not necessarily the one that would apply following a reboot. | ||
- | |||
- | ---- | ||
- | |||
- | ==== Check connectivity using ping ==== | ||
- | |||
- | You can verify that the path between two machines has at least the expected MTU using the ping command: | ||
- | |||
- | <code bash> | ||
- | ping -M do -c 4 -s 8972 192.168.0.1 | ||
- | </ | ||
- | |||
- | This transmits an ICMP echo request to the specified destination then waits for an ICMP echo reply. | ||
- | |||
- | The **-M do** option causes the DF (don't fragment) flag to be set, meaning that the packet should be dropped if it cannot remain in one piece at any point in its journey. | ||
- | |||
- | The **-s** option specifies the number of bytes of padding that should be added to the echo request. | ||
- | |||
- | If the test is successful then you should see a list of echo replies that were received: | ||
- | |||
- | <code bash> | ||
- | PING 192.168.0.1 (192.168.0.1) 8972(9000) bytes of data. | ||
- | 1480 bytes from 192.168.0.1: | ||
- | 1480 bytes from 192.168.0.1: | ||
- | 1480 bytes from 192.168.0.1: | ||
- | 1480 bytes from 192.168.0.1: | ||
- | </ | ||
- | |||
- | Note that the IP packet size (9000 bytes) is listed on the first line. You can use this to check that you requested the correct amount of padding. | ||
- | |||
- | If the test is unsuccessful then you should see an error in response to each echo request: | ||
- | |||
- | <code bash> | ||
- | PING 192.168.0.1 (192.168.0.1) 8972(9000) bytes of data. | ||
- | From 192.168.0.2 icmp_seq=1 Frag needed and DF set (mtu = 1500) | ||
- | From 192.168.0.2 icmp_seq=1 Frag needed and DF set (mtu = 1500) | ||
- | From 192.168.0.2 icmp_seq=1 Frag needed and DF set (mtu = 1500) | ||
- | From 192.168.0.2 icmp_seq=1 Frag needed and DF set (mtu = 1500) | ||
- | </ | ||
- | |||
- | Note that the MTU for the hop that failed is listed in the error message. | ||
- | |||
- | Path MTUs are recorded in the routing cache. This can interfere with testing, and in particular, can make a remote MTU restriction appear to be a local one. You can clear the cache using the ip route command: | ||
- | |||
- | <code bash> | ||
- | ip route flush cache | ||
- | </ | ||
- | |||
- | ---- | ||
- | |||
- | ===== Errors ===== | ||
- | |||
- | ==== Invalid argument ==== | ||
- | |||
- | An error of the form: | ||
- | |||
- | <code bash> | ||
- | SIOCSIFMTU: Invalid argument | ||
- | </ | ||
- | |||
- | indicates that the requested MTU was rejected by the kernel. | ||
- | |||
- | ---- | ||
- | |||
- | ===== Reference ===== | ||
- | |||
- | * Matt Mathis, [[http:// | ||
ubuntu/network/change_the_mtu_of_a_network_interface.1594805433.txt.gz · Last modified: 2020/07/15 09:30 by 127.0.0.1