-
-
Notifications
You must be signed in to change notification settings - Fork 289
Expand file tree
/
Copy pathapply-static-ip
More file actions
executable file
·28 lines (23 loc) · 749 Bytes
/
apply-static-ip
File metadata and controls
executable file
·28 lines (23 loc) · 749 Bytes
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
#!/bin/bash
#
# Immediately apply the current static IP config to the device.
# Exit on first failure.
set -e
# Echo commands before executing them, by default to stderr.
set -x
# Exit on unset variable.
set -u
# Check which OS is running.
OS_CODENAME="$(grep '^VERSION_CODENAME' /etc/os-release | cut --delimiter '=' --fields 2)"
# Ignore hangup signals to avoid exiting the shell when the network interface
# is flushed and a new IP is assigned. This was an issue when running the script
# manually via a remote shell.
trap '' HUP
if [[ "${OS_CODENAME}" == 'bullseye' ]]; then
ip address flush dev eth0
systemctl restart \
dhcpcd.service
else
nmcli connection down 'Wired connection 1'
nmcli connection up 'Wired connection 1'
fi