kit/other_scripts/systemd-network-enable-defa...

58 lines
1.2 KiB
Bash
Raw Permalink Normal View History

2022-09-14 22:09:19 +00:00
#!/bin/bash
# Run this script with "(sudo) bash <filename> <args>".
# Exit on error.
set -e
[[ ! "$1" == "yes" ]] && (
printf "
This script modifies networking and will reboot your system!
Please ensure you have backup access.
DO NOT USE THIS IF YOU HAVE NO DHCP OR NEED STATIC IP ADDRESSING!!
To confirm, please re-run this script with \"yes\"
\"%s yes\".\n" "$0"
exit 1;
)
cat << EOF > /etc/systemd/network/dhcp.network
2022-09-14 22:09:19 +00:00
[Match]
Name=*
[Network]
DHCP=yes
DNSOverTLS=opportunistic
2023-05-08 19:58:37 +00:00
DNS=9.9.9.9
2022-09-14 22:09:19 +00:00
2023-05-08 19:58:37 +00:00
DNS=149.112.112.112
2022-09-14 22:09:19 +00:00
# Link discovery causes some issues so disable it.
LLDP=no
EOF
# Before rebooting ensure old networking isn't started on boot.
systemctl disable networking
systemctl enable systemd-networkd
2023-05-22 23:22:51 +00:00
# Only enable systemd if it's installed.
(apt install systemd-resolved && \
# Enable systemd-resolved & link stub-resolv.conf.
systemctl enable --now systemd-resolved && \
ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf) || \
# Note that systemd-resolved is not available.
printf 'systemd-resolved not available! OK, skipping it...\n';
2022-09-14 22:09:19 +00:00
# Final warning.
printf 'Rebooting in 30 seconds, hit ctrl+c to cancel.\n'
sleep 30;
halt --reboot