设置 Linux MTU

set_mtu

a bash script to set mtu in linux Server

Usage

$ bash set_mtu.sh help
Usage:
  set_mtu.sh <action> <interface> <mtu>
  action: set|status
Example:
  bash set_mtu.sh set <eth0> <1600>
  bash set_mtu.sh status <eth0>   

Check MTU Status

$ bash set_mtu.sh status
Interface MTU status:
lo: 65536
eth0: 1500

# Check specific MTU status
$ bash set_mtu.sh status eth0
Interface MTU status:
eth0: 1500  

Set MTU

$  bash set_mtu.sh set eth0 1600
Interface eth0 exists.
MTU 1600 is a number.
[1/2] Start to set MTU of eth0 to 1600 temporarily -- Done.
Set MTU of eth0 to 1600 temporarily Successfully.
[2/2] Start to set MTU of eth0 to 1600 permanently.
[2.1] Setting MTU of eth0 to 1600 permanently in DHCP -- Done.
Set MTU of eth0 in DHCP to 1600 permanently Successfully.
[2.2] Setting MTU of eth0 to 1600 permanently in config file -- Done.
Set MTU of eth0 in config file to 1600 permanently Successfully.

# ignore when related setting is configured. 
$ bash set_mtu.sh set eth0 1600
Interface eth0 exists.
MTU 1600 is a number.
[1/2] Start to set MTU of eth0 to 1600 temporarily -- Skipped.
MTU of eth0 has already been set to 1600 temporarily.
[2/2] Start to set MTU of eth0 to 1600 permanently.
[2.1] Setting MTU of eth0 to 1600 permanently in DHCP -- Skipped.
MTU of eth0 in DHCP has been set to 1600 permanently.
[2.2] Setting MTU of eth0 to 1600 permanently in config file -- Skipped.
MTU of eth0 in config file has been set to 1600 permanently.

# You can use this command to configure MTU even some files are changed manually
$ cat /etc/sysconfig/network-scripts/ifcfg-eth0
BOOTPROTO=dhcp
DEVICE=eth0
HWADDR=fa:16:3e:4e:41:ae
ONBOOT=yes
STARTMODE=auto
TYPE=Ethernet
USERCTL=no

$ bash set_mtu.sh set eth0 1600
Interface eth0 exists.
MTU 1600 is a number.
[1/2] Start to set MTU of eth0 to 1600 temporarily -- Skipped.
MTU of eth0 has already been set to 1600 temporarily.
[2/2] Start to set MTU of eth0 to 1600 permanently.
[2.1] Setting MTU of eth0 to 1600 permanently in DHCP -- Skipped.
MTU of eth0 in DHCP has been set to 1600 permanently.
[2.2] Setting MTU of eth0 to 1600 permanently in config file -- Done.
Set MTU of eth0 in config file to 1600 permanently Successfully.

$ cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=dhcp
DEVICE=eth0
HWADDR=fa:16:3e:4e:41:ae
ONBOOT=yes
STARTMODE=auto
TYPE=Ethernet
USERCTL=no
MTU=1600   

Test Cases

  • Validation check about mtu type and range
  • Interface existing check
  • Interface config file existing check. e.g /etc/sysconfig/network-scripts/ifcfg-eth0
  • DHCP config file existing check. e.g /etc/dhcp/dhclient-eth0.conf
  • set_mtu_temporary function. e.g ip link set dev eth0 mtu 1500
  • set_mtu_permanent_in_dhcp
  • set_mtu_permanent_in_config_file
  • configuration persists after the VM reboots
  • test in OpenStack
  • test in AWS

Support

Any questions please reach out to liozza@163.com or create an issue directly.
GitHub: https://github.com/liozzazhang/set_mtu

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值