blob: 5385f3be2c93f195bde74b2e50707f869f261434 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
|
#!/bin/bash
function actually_just_show {
echo "The MTU of $iface is $nowmtu."
exit 0
}
function get_default_iface {
iface=$(ip a | grep "state UP" | grep -v "virbr0" | cut -d: -f2 | tr -d '[[:space:]]')
if [ "x" == "x$iface" ]
then
echo "No active iface"
exit 1
fi
}
function get_current_mtu {
nowmtu=$(</sys/class/net/$iface/mtu)
}
function get_new_mtu {
case "$nowmtu" in
1500) mtu=1492
;;
*) mtu=1500
;;
esac
}
function guess_at_remainder {
for i in $@; do
case "$i" in
show) actually_just_show
;;
[0-9]*) mtu=$i
;;
[a-zA-Z]*) iface=$i
;;
esac
done
}
OPTIND=1
get_default_iface
get_current_mtu
get_new_mtu
while getopts "i:m:" opt; do
case "$opt" in
i) iface=$OPTARG
;;
m) mtu=$OPTARG
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
guess_at_remainder $@
echo -n "Set MTU of $iface to $mtu? [Y/n] "
read yn
if [ "x${yn,,}" != "xn" ]; then
echo $mtu | sudo tee "/sys/class/net/$iface/mtu" > /dev/null
fi
|