How to check if a network MTU is set in Linux

LinuxLinuxBeginner
Practice Now

Introduction

In this lab, you will learn how to check the Maximum Transmission Unit (MTU) of a network interface in Linux using various methods. Understanding MTU is crucial for network performance and troubleshooting.

You will explore three different approaches: using the modern ip link show command, the traditional ifconfig utility, and by inspecting the network interface information directly within the /sys/class/net filesystem. By the end of this lab, you will be proficient in identifying the MTU setting for your network interfaces.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL linux(("Linux")) -.-> linux/PackagesandSoftwaresGroup(["Packages and Softwares"]) linux(("Linux")) -.-> linux/BasicFileOperationsGroup(["Basic File Operations"]) linux(("Linux")) -.-> linux/RemoteAccessandNetworkingGroup(["Remote Access and Networking"]) linux/BasicFileOperationsGroup -.-> linux/ls("Content Listing") linux/BasicFileOperationsGroup -.-> linux/cat("File Concatenating") linux/RemoteAccessandNetworkingGroup -.-> linux/ifconfig("Network Configuring") linux/RemoteAccessandNetworkingGroup -.-> linux/ip("IP Managing") linux/PackagesandSoftwaresGroup -.-> linux/apt("Package Handling") subgraph Lab Skills linux/ls -.-> lab-558738{{"How to check if a network MTU is set in Linux"}} linux/cat -.-> lab-558738{{"How to check if a network MTU is set in Linux"}} linux/ifconfig -.-> lab-558738{{"How to check if a network MTU is set in Linux"}} linux/ip -.-> lab-558738{{"How to check if a network MTU is set in Linux"}} linux/apt -.-> lab-558738{{"How to check if a network MTU is set in Linux"}} end

In this step, you will learn how to check the Maximum Transmission Unit (MTU) of a network interface using the ip link show command. The MTU is the largest size data packet that a network interface can handle without fragmentation. Understanding MTU is important for network troubleshooting and performance tuning.

The ip command is a powerful tool in Linux for managing network interfaces, routing, and tunnels. The link subcommand is used to display and modify network interfaces.

Open your terminal if it's not already open. You can do this by clicking the Xfce Terminal icon on the left side of your desktop.

Now, type the following command and press Enter:

ip link show

This command will display information about all network interfaces on your system. You will see output similar to this:

1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff

Look for the line corresponding to your primary network interface. In this environment, it's typically eth0. You will find the mtu value listed there. In the example above, the MTU for eth0 is 1500.

The lo interface is the loopback interface, which is used for communication within the system itself. Its MTU is usually much larger.

Take a moment to examine the output and identify the MTU for your eth0 interface.

Click Continue to proceed to the next step.

Verify MTU with ifconfig

In this step, you will use the ifconfig command to verify the MTU of your network interface. While ip is the modern command for network configuration, ifconfig is an older, but still commonly used, utility. It provides similar information about network interfaces.

First, let's install net-tools, which contains the ifconfig command. We'll use apt again, just like we did for htop.

Open your terminal if it's not already open.

Type the following command to install net-tools and press Enter:

sudo apt update
sudo apt install net-tools -y

The -y flag automatically answers "yes" to any prompts during the installation, making the process smoother.

Once the installation is complete, you can use the ifconfig command. Type the following command and press Enter:

ifconfig

This command will display configuration information for all active network interfaces. You will see output similar to this:

eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 172.17.0.2  netmask 255.255.0.0  broadcast 172.17.255.255
        inet6 fe80::42:acff:fe11:2  prefixlen 64  scopeid 0x20<link>
        ether 02:42:ac:11:00:02  txqueuelen 1000  (Ethernet)
        RX packets 123  bytes 12345 (12.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 123  bytes 12345 (12.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 123  bytes 12345 (12.0 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 123  bytes 12345 (12.0 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

Again, look for the section corresponding to eth0. You will find the mtu value listed there, confirming the value you saw with ip link show.

Using both ip and ifconfig can be helpful as different systems or documentation might use one over the other.

Click Continue to move on.

Inspect MTU in /sys/class/net

In this step, you will explore the /sys filesystem to find the MTU value. The /sys filesystem is a virtual filesystem that provides an interface to kernel data structures. It allows you to inspect and sometimes modify kernel parameters and device information.

Network interface information, including the MTU, is exposed through the /sys/class/net directory. Each network interface on your system will have a subdirectory here.

Open your terminal if it's not already open.

First, let's list the contents of the /sys/class/net directory to see the available network interfaces. Type the following command and press Enter:

ls /sys/class/net/

You should see a list of network interfaces, similar to the output of ip link show or ifconfig. In this environment, you will likely see eth0 and lo.

eth0  lo

Now, let's look inside the directory for our primary interface, eth0. Type the following command and press Enter:

ls /sys/class/net/eth0/

This will show you a list of files and directories that contain information about the eth0 interface.

addr_assign_type  broadcast    device       ifindex      mtu        phys_port_id  speed
address           carrier      dormant      iflink       napi_defer_hard_irqs  phys_port_name  statistics
addr_len          carrier_changes  duplex       link_mode    netdev_group  power         subsystem
bonding_slave     carrier_up_count  flags        lower_       operstate     proto_down_reason  tx_queue_len
bridge_slave      dev_id       gro_flush_timeout  name_assign_type  perms         qdisc         type

Notice the file named mtu. We can read the content of this file to get the MTU value. Use the cat command to display the content of the mtu file. Type the following command and press Enter:

cat /sys/class/net/eth0/mtu

You should see the MTU value printed to the terminal, which should be 1500.

1500

This method of checking the MTU by reading the /sys file provides a direct way to access kernel-level information about the network interface.

You have now successfully checked the MTU using three different methods: ip link show, ifconfig, and by inspecting the /sys filesystem. This demonstrates that there are often multiple ways to achieve the same task in Linux.

Click Continue to complete this lab.

Summary

In this lab, you learned how to check the Maximum Transmission Unit (MTU) of a network interface in Linux using three different methods. You first used the modern ip link show command to display detailed information about all network interfaces, including their MTU values. You then verified this information using the older but still common ifconfig command. Finally, you explored how to inspect the MTU value directly from the /sys/class/net filesystem, which provides a programmatic way to access network interface properties. These methods provide different ways to confirm the MTU setting, which is crucial for network troubleshooting and performance optimization.