-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrestart-network
More file actions
executable file
·85 lines (74 loc) · 2.55 KB
/
restart-network
File metadata and controls
executable file
·85 lines (74 loc) · 2.55 KB
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash
# SPDX-FileCopyrightText: 2015 - 2024 sudorook <daemon@nullcodon.com>
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program. If not, see <https://www.gnu.org/licenses/>.
set -euo pipefail
ROOT="$(dirname "${0}")"
source "${ROOT}"/globals
#
# Consider removing this. MAC address randomization is built into
# NetworkManager now, so use of macchanger is not needed. Set
# <iface>.cloned-mac-address=random in /etc/NetworkManager/NetworkManager.conf,
# and this whole script can be replaced entirely by:
#
# $ sudo systemctl restart NetworkManager.service
#
# Otherwise, to keep this script, implement the following fixes:
# - Parse the results of `ip link show` to figure out the interface names for
# the 'all' option.
# - Use getopt to parse command line options.
# - Print a message upon use describing the NetworkManager MAC address option.
# - Actually check that the MAC address of the interface(s) are actually
# changed.
#
# --A
#
! check_command macchanger && exit 3
function print_interfaces {
ip link show | grep "^[0-9]" | grep -v "virbr\|tun\|lo" |
cut -d ":" -f2 | sed -e 's/^\s\(.*\)$/ \1/g'
}
if [ "${#}" -ne 1 ]; then
show_error "Error. Specify the network interface to restart."
print_interfaces
exit 1
fi
iface="${1}"
if [ "${iface}" = "all" ]; then
sudo bash -c "\
systemctl stop NetworkManager.service && \
ip link set dev wlp3s0 down && \
ip link set dev enp0s25 down && \
macchanger -e wlp3s0 && \
macchanger -e enp0s25 && \
ip link set dev wlp3s0 up && \
ip link set dev enp0s25 up && \
systemctl start NetworkManager.service"
exit 0
fi
if test "$(ip link show | grep -c "${iface}")" -ne 0; then
sudo bash -c "\
systemctl stop NetworkManager.service && \
ip link set dev ${iface} down && \
macchanger -e ${iface} && \
ip link set dev ${iface} up && \
systemctl start NetworkManager.service"
exit 0
else
show_error "Interface ${iface@Q} doesn't exist. Pick from:"
print_interfaces
exit 1
fi