mirror of
https://gitea.blesmrt.net/mikaela/shell-things.git
synced 2024-11-29 06:29:36 +01:00
etc/resolv.conf-generate.bash: simple resolv.conf writer the way I want
This commit is contained in:
parent
fa9da0901d
commit
c00f750d96
31
etc/resolv.conf-generate.bash
Executable file
31
etc/resolv.conf-generate.bash
Executable file
@ -0,0 +1,31 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
set -x
|
||||||
|
|
||||||
|
# Require root or exit
|
||||||
|
if [ "$(id -u)" != "0" ]; then
|
||||||
|
echo "This script requires root." 1>&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# In case I am behind the /etc/resolv.conf, it's immutable and read-only,
|
||||||
|
# which won't allow it to be rewritten.
|
||||||
|
chattr -i /etc/resolv.conf
|
||||||
|
chmod +w /etc/resolv.conf
|
||||||
|
# Or it's a symlink to e.g. /run/systemd/resolve/stub-resolv.conf
|
||||||
|
rm -v /etc/resolv.conf
|
||||||
|
|
||||||
|
# Actual resolv.conf creation. OK, this could read resolv.conf in this
|
||||||
|
# directory, but I like this being self-contained.
|
||||||
|
# tee -p = operate in a more appropriate MODE with pipes.
|
||||||
|
printf 'nameserver ::1\nnameserver 127.0.0.1\nnameserver 127.0.0.53\noptions edns0 trust-ad timeout:1 attempts:5\nsearch .\n' | tee -p /etc/resolv.conf
|
||||||
|
|
||||||
|
# Remove all other permissions than everyone reading resolv.conf
|
||||||
|
chmod a=r /etc/resolv.conf
|
||||||
|
# Make resolv.conf immutable again so it's pretty sure nothing else edits it.
|
||||||
|
chattr +i /etc/resolv.conf
|
||||||
|
|
||||||
|
# Let's just see it's ok
|
||||||
|
ls -l /etc/resolv.conf
|
||||||
|
cat /etc/resolv.conf
|
||||||
|
|
||||||
|
set +x
|
Loading…
Reference in New Issue
Block a user