Monday, 8 June 2015

Networking: Concept of MTU

Maximum Transmission Unit (MTU) may vary from one network to another network. MTU of a network depends on the type of network and protocols used in the network.

As a standard, Ethernet cards MTU is fixed at 1500 bytes at the network layer.

The MTU refers to the largest packet that is allowed to be sent on the network. It will be strictly followed by all hosts and devices that transmit packets on that network.

For example: 

    Network 1   Network 2
     MTU 2000    MTU1500
Host 1-------^^**------------>Host 2
 ----->  -->  -->
       Packet 1 Packet2

Host 1 resides on Network 1, which has a MTU of 2000. Host 2 on the other side is part of Network 2 where the MTU is 1500. Any packet generating from Network 1 will be of size 2000 bytes. When this packet is passed to Network 2 through router, it has to be broken down to two packets of (1500 + 500 ) bytes. This is because network 2 allows only packets below 1500 bytes. Also, when the packet reached Host 2, it will again need to be assembled.

Sometimes we may need to increase the MTU of an interface to improve the throughput of high-speed Ethernet. Enternet cards MTU is always fixed at 1500 bytes. This is to make them compatible for 10 and 100 megabit networks. However, when it comes to gigabit networks this will be a bottleneck in improving performance. Most modern networking equipment is capable of handling larger frames but it needs to be configured to do so. Frames which take advantage of this ability are known as ‘jumbo frames’, and 9000 bytes is a popular choice for the MTU.

How to set MTU for an Ethernet card temporarily:

You can change the MTU of an interface as below:
ifconfig eth0 mtu 9000

This is temporary and  will be restored to old value on reboot.

How to find out MTU of an Ethernet card:

The MTU of an interface can be found out by using commands "netstat -i" and "ifconfig" as below:


ping -M do -c 4 -s 8972

The above command transmits an ICMP echo request to the specified destination then waits for an ICMP echo reply. This is to check the behaviour of eth0, it would be best to choose a destination on the same subnet in the first instance. Both machines must have a sufficiently large MTU if the test is to succeed.

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 -c option sets the number of pings.

The -s option specifies the number of bytes of padding that should be added to the echo request. In addition to this number there will be 20 bytes for the internet protocol header, and 8 bytes for the ICMP header and timestamp. The amount of padding should therefore be 28 bytes less than the network-layer MTU that you are trying to test (9000 − 28 = 8972).

If the test is successful then you should see a list of echo replies that were received:

PING ( 8972(9000) bytes of data.
1480 bytes from icmp_seq=1 ttl=64 time=0.241 ms
1480 bytes from icmp_seq=2 ttl=64 time=0.583 ms
1480 bytes from icmp_seq=3 ttl=64 time=0.140 ms
1480 bytes from icmp_seq=4 ttl=64 time=0.123 ms

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:

PING ( 8972(9000) bytes of data.
From icmp_seq=1 Frag needed and DF set (mtu = 1500)
From icmp_seq=1 Frag needed and DF set (mtu = 1500)
From icmp_seq=1 Frag needed and DF set (mtu = 1500)
From 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. This is not necessarily the MTU for the entire path, only the first MTU that was found to be too small.

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:
ip route flush cache


When MTU of  a device need to be set permanently, the "ifcfg-eth0" file of device will look as below:


Kool :)

No comments:

Post a Comment

Note: only a member of this blog may post a comment.