Determine MTU size using ping

Normally the MTU size should be set correctly using Path MTU discovery, but this may not always work.

The trouble is that the problems caused by an incorrect MTU size can be quite subtle, for example it may be possible to browse to a web server using but for file transfers to fail, or for connections to a chat server to work, but for the information about who is on-line to be incomplete or missing.

If you suspect that the problem is the MTU size then the first problem is to work out what the MTU size is for the network link. To do this you can use ‘ping’ to send a packet of the required size with the do not fragment bit set (it is also a good idea to use a packet count of one as there isn’t any point in sending more network traffic than you need to).

Note – The size specified in the ping command is actually the number of data bytes to send so this needs to be 28 bytes smaller than the actual packet size to allow for size of the packet header.

ping -s $((1500 - 28)) -D 8.8.8.8 -c 1
PING 8.8.8.8 (8.8.8.8) 1472(1500) bytes of data.
 
--- 8.8.8.8 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms
 
$

As a first attempt I’ve (rather optimistically) chosen an MTU size of 1500 bytes, this would be normal on a LAN but if very unlikely to work on an internet connection!

In my case I already know the MTU size is 1492 bytes so I’ll try that next.

ping -s $((1492 - 28)) -D 8.8.8.8 -c 1
PING 8.8.8.8 (8.8.8.8) 1464(1492) bytes of data.
[1551655205.799011] 1472 bytes from 8.8.8.8: icmp_seq=1 ttl=120 time=9.16 ms
 
--- 8.8.8.8 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 9.160/9.160/9.160/0.000 ms
$

If you didn’t know the MTU size you could then just try different values until you found the largest one that worked, but there is a quicker way (depending on your version of ping).

ping -s $((1500 - 28)) -M do 8.8.8.8 -c 1
PING 8.8.8.8 (8.8.8.8) 1472(1500) bytes of data.
ping: local error: Message too long, mtu=1492
 
--- 8.8.8.8 ping statistics ---
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms
 
$

Advertisements
This entry was posted in Linux, Networking and tagged , , , , . Bookmark the permalink.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.