#!/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; ) # Enable systemd-resolved & link stub-resolv.conf. systemctl enable --now systemd-resolved ln -sf /var/run/systemd/resolve/stub-resolv.conf /etc/resolv.conf cat << EOF > /etc/systemd/network/dhcp.network [Match] Name=* [Network] DHCP=yes DNSOverTLS=opportunistic DNS=1.1.1.1 DNS=1.0.0.1 # 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 # Final warning. printf 'Rebooting in 30 seconds, hit ctrl+c to cancel.\n' sleep 30; halt --reboot