Check mtu linux ping

Значение MTU в Linux

MTU — maximum transmission unit — максимальный размер пакета или фрейма в байтах, который может быть отправлен единовременно без фрагментации. Узнать значение и поменять MTU в Linux можно используя утилиту ip. Чтобы изменения сохранялись после перезагрузки требуется продублировать новое значение в сетевых настройках.

Как узнать значение и поменять MTU в Linux

Узнать значение MTU для всех интерфейсов можно выполнив в консоли команду ip link

1: lo: mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
link/ether 54:52:00:91:96:85 brd ff:ff:ff:ff:ff:ff

Чаще всего встречается 1500 — это значение по умолчанию для Ethernet интерфейсов.

Поменять MTU на сервере с Debian можно так:

ip link set dev eth0 mtu 1400

На скриншоте показан процесс смены mtu:

Значение MTU в Linux

Новое значение выделено, это 1400, оно начнет использоваться для интерфейса сразу. После перезагрузки эти изменения не сохранятся.

Чтобы сделать изменения постоянными нужно отредактировать файл /etc/network/interfaces

Для CentOS это скрипты /etc/sysconfig/network-scripts/*, для других систем иначе — для Debian также возможны варианты, но чаще всего это /etc/network/interfaces

К нужному интерфейсу достаточно дописать mtu 1400 отдельной строкой

IFACE при этом заменить именем интерфейса, таким как eth0

Если настройки сети выдаются DHCP, то секция примет такой вид:

iface eth0 inet dhcp
pre-up /sbin/ifconfig $IFACE mtu 1454

Как проверить MTU для внешнего сервера

Для сервера, к которому нет доступа по SSH MTU можно узнать экспериментальным путем. Значение может потребоваться при поиске сетевых неполадок.

Это делается за счет опции -M do утилиты ping.

ICMP пакеты при этом будут отправляться с заданным MTU, из ответа будет видно реальное значение.

PING ya.ru (87.250.250.242) 1572(1600) bytes of data.
ping: local error: Message too long, mtu=1500

— ya.ru ping statistics —
1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms

28 байт вычитается, поскольку они отданы под заголовки IP и ICMP.

При установке 1500 байт PING проходит успешно.

PING ya.ru (87.250.250.242) 1472(1500) bytes of data.
1480 bytes from ya.ru (87.250.250.242): icmp_seq=1 ttl=57 time=32.0 ms

— ya.ru ping statistics —
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 32.040/32.040/32.040/0.000 ms

Читайте про iface inet — директиву, которую можно увидеть в /etc/network/interfaces

Источник

Как узнать значение MTU

Обновлено

Обновлено: 27.09.2017 Опубликовано: 23.06.2016

Читайте также:  Символы конца строки linux

Windows

Нажмите комбинащию клавишь Win + R

В появившемся окне введите cmd и нажмите OK

Запуск командной строки

В открывшемся черном окне введите команду:

netsh interface ipv4 show subinterfaces

В первой колонке ответа мы увидим значение MTU:

Команда для определения значения MTU

* в данном примере, значение MTU равно 1500 для сетевого адаптера Ethernet.

Linux

ip address

В более современных системах используется утилита для работы с сетевыми интерфейсами — ip address. Вводим команду:

В полученном результате находим нужный сетевой интерфейс и строчку на подобие:

eth0: mtu 1500 qdisc pfifo_fast state UP qlen 1000

* то, что мы ищем — mtu 1500.

ifconfig

В более ранних системах или с установленным ifconfig вводим:

* где eth0 — сетевой адаптер, для которого хотим узнать MTU.

В полученном результате находим что-то на вроде:

* где mtu 1500 — наше значение.

FreeBSD

В данной системе работаем с уже описанным выше ifconfig:

Провайдера

Чтобы определить оптимальное значение MTU для нашего сетевого адаптера, подключенного к сети Интернет, необходимо узнать значение, используемое на оборудовании поставщика.

Для этого выполняем ping с запретом фрагментации сетевых пакетов (-f) и выставлением определенного размера пакета (-l):

* 1472 будет соответствовать MTU — 1500, так как к пакету мы должны еще прибавить 28 (заголовок).

Наша задача — подобрать значение пакета, при котором будет идти пинг:

Ответ от 90.156.242.197: число байт=1472 время=13мс TTL=56
Ответ от 90.156.242.197: число байт=1472 время=12мс TTL=56

Требуется фрагментация пакета, но установлен запрещающий флаг.
Требуется фрагментация пакета, но установлен запрещающий флаг.

Значит значение -l нужно уменьшить, пока сигнал не начнет проходить.

Находим значение, которое стоит на границе с ошибкой и прибавляем к нему заголовок пакета — 28. Так мы получаем наше оптимальное MTU.

На данный момент большинство Интернет провайдеров предоставляет услуги связи с фрагментом в 1500. Старые подключения от Ростелеком или подключения на основе PPPoE могут работать на меньших значениях.

Источник

Ping MTU – Find a Path’s MTU using PING Command

ping mtu tutorial

In some cases, higher-layer protocols may create large-size packets that not all network paths can support, such as the case of the jumbo frames.

These large packets (or frames) exceed the conventional Ethernet 1500 bytes of MTU (Maximum Transmission Unit).

So, the routers along the path with a default Ethernet MTU in their interfaces will fragment any of these large size packets that threaten to hurt their performance.

An improperly configured MTU can lead to failed transfers and intermittent connectivity.

But what is more daunting is that troubleshooting these kinds of problems can be really challenging.

Fortunately, we can do advanced troubleshooting and find the path MTU with the precious simple networking tool — The Ping Command.

How Does Path MTU Discovery Work?

The default Ethernet II MTU size is 1500 bytes, which is the largest size allowed in most of the Internet.

Although this value is known to be suitable for most environments, it is sometimes adjusted to a higher or lower value.

Adjusting MTU values can help match and improve the capacity of the network.

Читайте также:  Информация о процессоре linux mint

Larger MTU values can lead to lower network overhead, while a smaller MTU can help decrease the network delay.

How do routers discover MTU in a path?

Modern routers and endpoints use a process known as Path MTU Discovery (PMTUD) to find the path MTU, which is smaller than its interface MTU.

The goal of this process is to find the MTU size of a path while avoiding IP fragmentation.

The PMTUD works by setting the “Don’t Fragment (DF)” flag bit ON, within the IP packet header.

Routers along the path will receive these incoming packets and compare them with their MTU.

If the router interface’s MTU is smaller than the packet’s, and the packet contains the “Don’t Fragment” flag bit on, then the router will be forced to drop the packet and send back an ICMP Fragmentation Needed error message.

Knowing that the path MTU is too large, the source can adjust its packet’s MTU accordingly.

The process is repeated until the MTU has the right size to go through the entire path without fragmentation.

Simulating the Path MTU Discovery Process

You can simulate the Path MTU Discovery process using the ICMP Ping command with additional flags.

Perform a Ping to the target destination address. It can be the local gateway, a server, or a remote IP address.

To do this, we will be using the following additional Ping Flags:

Start by adjusting the TCP send buffer (size) with the “-l” flag. In the following Windows OS screenshot, you can see that we are sending an ICMP packet of 2000 bytes in size to the public IP 1.1.1.1

Simulating the Path MTU Discovery Process

The Ethernet packet with a size of 2000 bytes is generally larger than most MTU in typical networks.

The packet is successfully going through the path and reaching its destination because it is being fragmented by the routers along the path.

Now, let’s see what happens when we set the “Don’t Fragment” flag, with the following command:

ping (destination IP) (-f) (-l (packet size))

Windows Ping Destination

When a packet is too large for a path MTU, a router would usually fragment it into pieces for a safer delivery.

But, as you can see from the screenshot above, now the destination returns a “Packet needs to be fragmented but DF set”.

Since we are choosing not to fragment packets, all the routers along the path will see no choice than to drop the packet.

For other Operating Systems:

ping (-M do) (-s (packet size)) (destination)

ping (-D) (-s (packet size)) (destination)

How to Find the Path’s MTU with Ping?

Now, to find the path MTU with a Ping command, you would need to repeat the process shown before and adjust the packet size every time.

You will ultimately find the path MTU by trial and error.

In the previous ping test, we used the 2000 bytes as the packet size.

You would probably want to start with a number around 1800-2000 bytes and move down every couple of 100 bytes until you get a successful ping reply.

Читайте также:  Ospf routing in linux

As you can see in the following screenshot, we started with 1800, tested with 1500, until 1400 finally gave a successful reply.

That means the path MTU between our source and destination is somewhere between 1400 and 1500 bytes.

The next step would be to move the size up between 10-50 bytes until you get another successful reply.

We tested with 1450 bytes and got a reply, which means our value is above that.

Repeating this process led us to find the value, which is 1452 bytes.

The routers along the path were still fragmenting 1453 bytes (but not 1452). They considered 1453 to be too large to traverse the path.

But 1452 was the first proper packet size that returned a successful ICMP reply. My MTU value 1452 is common in Ethernet II.

We have to take into account the size of the TCP/IP header, which can range between 20-60 bytes. The header size varies according to the transmission media.

According to a chart from Wikipedia.

Wikipedia chart

My Point-to-Point Protocol over Ethernet (PPPoE) header takes up 8 bytes in size, while the IPv6 header accounts for 40 bytes in size. So, the size of my TCP/IP header is 48 bytes (40+8).

Let’s take the packet size that gave us the ping reply (1452 bytes) and add it to the header size (48 bytes).

That leads us to the real MTU size, which is 1500 bytes, the common Ethernet MTU.

1452 is the data payload size or Maximum Segment Size (MSS), that results from the 1500 MTU.

Ping MTU FAQs

What is the default MTU size for ping?

The default MTU size for ping is typically 1500 bytes, but it can vary depending on the network and operating system.

How can I change the MTU size for ping?

To change the MTU size for ping, you can use the -l option followed by the desired packet size in bytes. For example: ping -l

Why would I want to change the MTU size for ping?

You may want to change the MTU size for ping to test the maximum size of packets that can be transmitted over a network or to test the performance of a network with different MTU sizes.

What is the relationship between MTU and packet loss in ping?

The relationship between MTU and packet loss in ping is that a larger MTU size can result in more packets being lost if the network has a lower MTU size limit. This is because larger packets may be fragmented and some fragments may be lost in transit.

How can I determine the optimal MTU size for a network?

To determine the optimal MTU size for a network, you can use a tool such as «ping -f -l » to incrementally increase the packet size and check for packet loss. The optimal MTU size is the largest size with no packet loss.

Источник

Оцените статью
Adblock
detector