forked from 45Drives/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoffline-mode.sh
60 lines (56 loc) · 1.33 KB
/
offline-mode.sh
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
#!/bin/bash
usage() { # Help
cat << EOF
Usage: ./offline-mode.sh -m <enable|disable> -i <interface_name>
[-m] Mode. Required. Enable turns internet access OFF, Disable turns internet ON
[-i] Interface. Required. Active interface name
[-g] Gateway Address. Optional. Defaults to 192.168.0.1
[-h] Displays this message
EOF
exit 1
}
GATEWAY="192.168.0.1"
INTERFACES=( $(ls /sys/class/net | grep -v lo) )
while getopts 'm:i:g:h' OPTION; do
case ${OPTION} in
m)
MODE="${OPTARG}"
;;
i)
INTERFACE="${OPTARG}"
;;
g)
GATEWAY="${OPTARG}"
;;
h)
usage
;;
esac
done
if [ -z $MODE ] ; then
usage
elif [ "$MODE" != "enable" ] && [ "$MODE" != "disable" ]; then
usage
fi
if [ -z $INTERFACE ] ; then
usage
elif [[ ! " ${INTERFACES[*]} " =~ " $INTERFACE " ]];then
echo "Network interface does not exist on server"
exit 1
fi
case $MODE in
enable)
echo "removing gateway on $INTERFACE"
nmcli connection modify "$INTERFACE" ipv4.gateway "0.0.0.0"
;;
disable)
echo "adding gateway address $GATEWAY on $INTERFACE "
nmcli connection modify "$INTERFACE" ipv4.gateway "$GATEWAY"
;;
*)
echo "input options are: enable or disable"
exit 1
;;
esac
echo "Reloading $INTERFACE"
nmcli connection up "$INTERFACE"