In some cases, networks may require changes to the MTU of an interface to operate properly.
The MTU setting can be seen using the ifconfig command as below:
ziggy@ip-172-31-19-9:~$ ifconfig
enp0s5: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 9000
inet 172.31.19.9 netmask 255.255.240.0 broadcast 172.31.31.255
inet6 fe80::870:19ff:fe23:d4c3 prefixlen 64 scopeid 0x20<link>
ether 0a:70:19:23:d4:c3 txqueuelen 1000 (Ethernet)
RX packets 565 bytes 71993 (71.9 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 478 bytes 59564 (59.5 KB)
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 76 bytes 6830 (6.8 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 76 bytes 6830 (6.8 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Testing for the MTU can be done via the ping command, if you do not know it in advance.
Ping your default GW or another live closest node in your LAN by packets with "do not fragment" option and with specified packet size. Change packet size and find the limit size which is responded by the peer node:
ping 192.168.1.1 -c 2 -M do -s 2000
ping 192.168.1.1 -c 2 -M do -s 1500
ping 192.168.1.1 -c 2 -M do -s 1400
ping 192.168.1.1 -c 2 -M do -s 1472
ping 192.168.1.1 -c 2 -M do -s 1473
If packet size is bigger than MTU then ping response is e.g.:
ping: local error: message too long, mtu=1500
Please note that packet size you use in the ping command (-s option) must be MTU minus 18 bytes, i.e. for instance 1500-18=1472.
The response if the MTU is not exceeded is e.g.
2 packets transmitted, 2 received, 0% packet loss, time 1014ms
For testing applications, the MTU setting can be modified temporarily using the ifcommand:
sudo ifconfig <interfacename> mtu <mtu value>
For example, from the system used above:
ziggy@ip-172-31-19-9:~$ sudo ifconfig enp0s5 mtu 1500
ziggy@ip-172-31-19-9:~$ ifconfig
enp0s5: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.31.19.9 netmask 255.255.240.0 broadcast 172.31.31.255
inet6 fe80::870:19ff:fe23:d4c3 prefixlen 64 scopeid 0x20<link>
ether 0a:70:19:23:d4:c3 txqueuelen 1000 (Ethernet)
RX packets 1086 bytes 109676 (109.6 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 891 bytes 109499 (109.4 KB)
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 80 bytes 7182 (7.1 KB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 80 bytes 7182 (7.1 KB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
Setting the MTU permanently
To set the MTU to survive rebooting, the netplan configuration must be modified.
ziggy@ip-172-31-19-9:~$ cd /etc/netplan
ziggy@ip-172-31-19-9:/etc/netplan$ ls
50-cloud-init.yaml
ziggy@ip-172-31-19-9:/etc/netplan$ sudo vi 50-cloud-init.yaml
The MTU setting should be added to the interface within the file:
# This file is generated from information provided by the datasource. Changes
# to it will not persist across an instance reboot. To disable cloud-init's
# network configuration capabilities, write a file
# /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg with the following:
# network: {config: disabled}
network:
ethernets:
enp0s5:
dhcp4: true
dhcp6: false
match:
macaddress: 0a:70:19:23:d4:c3
set-name: enp0s5
mtu: <MTU Size>
version: 2
Once the file is saved, use the command:
sudo netplan try
Once you made the changes to the following file $sudo vi /etc/netplan/50-cloud-init.yaml, please follow the below process
- Create the config file99-disable-network-config.cfg on this path/etc/cloud/cloud.cfg.d/
- Edit the config file99-disable-network-config.cfg and add network: {config: disabled}
- Save and close the config file
Comments
0 comments