Skip to content

Commit 20a4e81

Browse files
Force use of systemd-resolved after files instead of before. #456
1 parent 27d14da commit 20a4e81

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
#!/bin/bash
22
#######################
3-
# Enable systemd-reloved and make sure the old nscd is disabled
3+
# Enable systemd-resolved and make sure the old nscd is disabled
44
#######################
55

66
systemctl disable --now nscd 2> /dev/null
77
systemctl enable --now systemd-resolved
8-
grep -q -e '^hosts:\s\+.*resolve.*$' /etc/nsswitch.conf
9-
if [ $? -eq 1 ]; then
10-
sed -i -E 's/^hosts:(\s+)(.+)$/hosts:\1resolve \2/g' /etc/nsswitch.conf
11-
fi
8+
9+
# Put resolved into the name service switch configuration. It needs
10+
# to go before 'files' because, even though systemd-resolved claims to
11+
# synthesize entries for the local system, it doesn't. That causes
12+
# problems trying to resolve the local host's name.
13+
14+
# Steps:
15+
# - Remove any instance of 'resolve'
16+
# - If there's a 'files' insert 'resolve' after that
17+
# - If there's no 'files', insert 'resolve' first
18+
sed -i -E \
19+
-e '/^hosts:/ s/resolve[[:space:]]?//' \
20+
-e '/^hosts:.*files/ s/files/files resolve/' \
21+
-e '/^hosts:.*files/! s/^(hosts:[[:space:]]*)/\1resolve /' \
22+
/etc/nsswitch.conf

0 commit comments

Comments
 (0)