shell-things/etc/NetworkManager-resolv.conf-restore.bash

40 lines
1.0 KiB
Bash
Raw Permalink Normal View History

#!/usr/bin/env bash
set -x
# I learned that not only systemd-resolved does this, but NetworkManager as
# well. I think it's even less likely I use this than the systemd-resolved
# one, but anyway
# I know there are old versions that used something else, but I don't remember
# that name and they are ancient.
if ! hash nmcli 2> /dev/null; then
echo "You don't seem to have NetworkManager (or nmcli) installed." 1>&2
exit 1
fi
# Require root or exit
if [ "$(id -u)" != "0" ]; then
echo "This script requires root." 1>&2
exit 1
fi
# It's pointless to make a dead symlink as it must be running
systemctl enable --now NetworkManager.service
# In case I am behind the /etc/resolv.conf, it's immutable and read-only,
# which won't allow it to be rewritten.
chattr -V -i /etc/resolv.conf
chmod -v +w /etc/resolv.conf
# It must be removed if it's not a symlink
rm -v /etc/resolv.conf
# and finally making the symlink
ln -sfv /var/run/NetworkManager/resolv.conf /etc/resolv.conf
# Let's just see it's ok
ls -l /etc/resolv.conf
cat /etc/resolv.conf
set +x