Skip to content

Commit

Permalink
bootstrap: support systemd-resolved when setting a prepender
Browse files Browse the repository at this point in the history
Set DNS_IP via systemd-resolved if the service is running
  • Loading branch information
vrutkovs committed Jun 14, 2021
1 parent e9fa111 commit 97d2611
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,27 @@ case "$STATUS" in
logger -s "NM local-dns-prepender triggered by ${1} ${2}."
DNS_IP="127.0.0.1"
set +e
logger -s "NM local-dns-prepender: Checking if local DNS IP is the first entry in resolv.conf"
if grep nameserver /etc/resolv.conf | head -n 1 | grep -q "$DNS_IP" ; then
logger -s "NM local-dns-prepender: local DNS IP already is the first entry in resolv.conf"
exit 0
if systemctl -q is-enabled systemd-resolved; then
>&2 echo "NM resolv-prepender: Setting up systemd-resolved for local DNS"
if [[ ! -f /etc/systemd/resolved.conf.d/60-kni.conf ]]; then
>&2 echo "NM resolv-prepender: Creating /etc/systemd/resolved.conf.d/60-kni.conf"
mkdir -p /etc/systemd/resolved.conf.d
echo "[Resolve]" > /etc/systemd/resolved.conf.d/60-kni.conf
echo "DNS=$DNS_IP" >> /etc/systemd/resolved.conf.d/60-kni.conf
if systemctl -q is-active systemd-resolved; then
>&2 echo "NM resolv-prepender: restarting systemd-resolved"
systemctl restart systemd-resolved
fi
fi
else
logger -s "NM local-dns-prepender: Looking for '# Generated by NetworkManager' in /etc/resolv.conf to place 'nameserver $DNS_IP'"
sed -i "/^# Generated by.*$/a nameserver $DNS_IP" /etc/resolv.conf
logger -s "NM local-dns-prepender: Checking if local DNS IP is the first entry in resolv.conf"
if grep nameserver /etc/resolv.conf | head -n 1 | grep -q "$DNS_IP" ; then
logger -s "NM local-dns-prepender: local DNS IP already is the first entry in resolv.conf"
exit 0
else
logger -s "NM local-dns-prepender: Looking for '# Generated by NetworkManager' in /etc/resolv.conf to place 'nameserver $DNS_IP'"
sed -i "/^# Generated by.*$/a nameserver $DNS_IP" /etc/resolv.conf
fi
fi
;;
*)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,27 @@ case "$STATUS" in
logger -s "NM local-dns-prepender triggered by ${1} ${2}."
DNS_IP="127.0.0.1"
set +e
logger -s "NM local-dns-prepender: Checking if local DNS IP is the first entry in resolv.conf"
if grep nameserver /etc/resolv.conf | head -n 1 | grep -q "$DNS_IP" ; then
logger -s "NM local-dns-prepender: local DNS IP already is the first entry in resolv.conf"
exit 0
if systemctl -q is-enabled systemd-resolved; then
>&2 echo "NM resolv-prepender: Setting up systemd-resolved for local DNS"
if [[ ! -f /etc/systemd/resolved.conf.d/60-kni.conf ]]; then
>&2 echo "NM resolv-prepender: Creating /etc/systemd/resolved.conf.d/60-kni.conf"
mkdir -p /etc/systemd/resolved.conf.d
echo "[Resolve]" > /etc/systemd/resolved.conf.d/60-kni.conf
echo "DNS=$DNS_IP" >> /etc/systemd/resolved.conf.d/60-kni.conf
if systemctl -q is-active systemd-resolved; then
>&2 echo "NM resolv-prepender: restarting systemd-resolved"
systemctl restart systemd-resolved
fi
fi
else
logger -s "NM local-dns-prepender: Looking for '# Generated by NetworkManager' in /etc/resolv.conf to place 'nameserver $DNS_IP'"
sed -i "/^# Generated by.*$/a nameserver $DNS_IP" /etc/resolv.conf
logger -s "NM local-dns-prepender: Checking if local DNS IP is the first entry in resolv.conf"
if grep nameserver /etc/resolv.conf | head -n 1 | grep -q "$DNS_IP" ; then
logger -s "NM local-dns-prepender: local DNS IP already is the first entry in resolv.conf"
exit 0
else
logger -s "NM local-dns-prepender: Looking for '# Generated by NetworkManager' in /etc/resolv.conf to place 'nameserver $DNS_IP'"
sed -i "/^# Generated by.*$/a nameserver $DNS_IP" /etc/resolv.conf
fi
fi
;;
*)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,27 @@ case "$STATUS" in
logger -s "NM local-dns-prepender triggered by ${1} ${2}."
DNS_IP="127.0.0.1"
set +e
logger -s "NM local-dns-prepender: Checking if local DNS IP is the first entry in resolv.conf"
if grep nameserver /etc/resolv.conf | head -n 1 | grep -q "$DNS_IP" ; then
logger -s "NM local-dns-prepender: local DNS IP already is the first entry in resolv.conf"
exit 0
if systemctl -q is-enabled systemd-resolved; then
>&2 echo "NM resolv-prepender: Setting up systemd-resolved for local DNS"
if [[ ! -f /etc/systemd/resolved.conf.d/60-kni.conf ]]; then
>&2 echo "NM resolv-prepender: Creating /etc/systemd/resolved.conf.d/60-kni.conf"
mkdir -p /etc/systemd/resolved.conf.d
echo "[Resolve]" > /etc/systemd/resolved.conf.d/60-kni.conf
echo "DNS=$DNS_IP" >> /etc/systemd/resolved.conf.d/60-kni.conf
if systemctl -q is-active systemd-resolved; then
>&2 echo "NM resolv-prepender: restarting systemd-resolved"
systemctl restart systemd-resolved
fi
fi
else
logger -s "NM local-dns-prepender: Looking for '# Generated by NetworkManager' in /etc/resolv.conf to place 'nameserver $DNS_IP'"
sed -i "/^# Generated by.*$/a nameserver $DNS_IP" /etc/resolv.conf
logger -s "NM local-dns-prepender: Checking if local DNS IP is the first entry in resolv.conf"
if grep nameserver /etc/resolv.conf | head -n 1 | grep -q "$DNS_IP" ; then
logger -s "NM local-dns-prepender: local DNS IP already is the first entry in resolv.conf"
exit 0
else
logger -s "NM local-dns-prepender: Looking for '# Generated by NetworkManager' in /etc/resolv.conf to place 'nameserver $DNS_IP'"
sed -i "/^# Generated by.*$/a nameserver $DNS_IP" /etc/resolv.conf
fi
fi
;;
*)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,27 @@ case "$STATUS" in
fi
EOF
set +e
logger -s "NM local-dns-prepender: Checking if local DNS IP is the first entry in resolv.conf"
if grep nameserver /etc/resolv.conf | head -n 1 | grep -q "$DNS_IP" ; then
logger -s "NM local-dns-prepender: local DNS IP already is the first entry in resolv.conf"
exit 0
if systemctl -q is-enabled systemd-resolved; then
>&2 echo "NM resolv-prepender: Setting up systemd-resolved for local DNS"
if [[ ! -f /etc/systemd/resolved.conf.d/60-kni.conf ]]; then
>&2 echo "NM resolv-prepender: Creating /etc/systemd/resolved.conf.d/60-kni.conf"
mkdir -p /etc/systemd/resolved.conf.d
echo "[Resolve]" > /etc/systemd/resolved.conf.d/60-kni.conf
echo "DNS=$DNS_IP" >> /etc/systemd/resolved.conf.d/60-kni.conf
if systemctl -q is-active systemd-resolved; then
>&2 echo "NM resolv-prepender: restarting systemd-resolved"
systemctl restart systemd-resolved
fi
fi
else
logger -s "NM local-dns-prepender: Looking for '# Generated by NetworkManager' in /etc/resolv.conf to place 'nameserver $DNS_IP'"
sed -i "/^# Generated by.*$/a nameserver $DNS_IP" /etc/resolv.conf
logger -s "NM local-dns-prepender: Checking if local DNS IP is the first entry in resolv.conf"
if grep nameserver /etc/resolv.conf | head -n 1 | grep -q "$DNS_IP" ; then
logger -s "NM local-dns-prepender: local DNS IP already is the first entry in resolv.conf"
exit 0
else
logger -s "NM local-dns-prepender: Looking for '# Generated by NetworkManager' in /etc/resolv.conf to place 'nameserver $DNS_IP'"
sed -i "/^# Generated by.*$/a nameserver $DNS_IP" /etc/resolv.conf
fi
fi
{{end}}
;;
Expand Down

0 comments on commit 97d2611

Please sign in to comment.