#!/bin/bash # Run this script with "(sudo) bash ". # 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 [Match] Name=* [Network] DHCP=yes DNSOverTLS=opportunistic DNS=9.9.9.9 DNS=149.112.112.112 # 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 # 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'; # Final warning. printf 'Rebooting in 30 seconds, hit ctrl+c to cancel.\n' sleep 30; halt --reboot