Skip to content
This repository has been archived by the owner on Jan 23, 2024. It is now read-only.

Added DNS support #51

Open
wants to merge 1 commit into
base: devel
Choose a base branch
from
Open

Added DNS support #51

wants to merge 1 commit into from

Conversation

unqueued
Copy link
Contributor

@unqueued unqueued commented Mar 4, 2020

I can think of a few ways to have done this. Is this way keeping in line with how it should be done?

Comment on lines 15 to 17
for i in $dns ; do
echo nameserver $i >> /etc/resolv.conf
done
Copy link
Contributor

@dywisor dywisor Mar 19, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

disable globbing with set -f; haven't checked whether you could inject wildcards * via DHCP, but there's no need to take that risk

set -f
if [ -n "${dns}" ]; then
    printf 'nameserver %s\n' ${dns} >> /etc/resolv.conf
fi
set +f

printf implicitly loops over all items in $dns

EDIT: check non-empty dns beforehand, printf might write an empty nameserver line otherwise.

;;

echo -n > /etc/resolv.conf
[ -n "$domain" ] && echo search $domain >> /etc/resolv.conf
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use quoting to be safe:

[ -z "${domain}" ] || printf 'search %s\n' "${domain}" >> /etc/resolv.conf

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be even futher reduced to [ "${domain}" ] && printf 'search %s\n' "${domain}" >> /etc/resolv.conf, but I somewhat prefer full if statements.

Comment on lines 13 to 17
echo -n > /etc/resolv.conf
[ -n "$domain" ] && echo search $domain >> /etc/resolv.conf
for i in $dns ; do
echo nameserver $i >> /etc/resolv.conf
done
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entire section could be written as a group writing to /etc/resolv.conf

{
    [ -z "${domain}" ] || printf 'search %s\n' "${domain}"
    set -f
    printf 'nameserver %s\n' ${dns} >> /etc/resolv.conf
    set +f
} > /etc/resolv.conf

@dywisor
Copy link
Contributor

dywisor commented Mar 19, 2020

Your approach bypasses the mechanism that dhcp-query writes binit_ variables to a temporary file for /init to pick up. This technique allows to have uniform network configuration regardless of whether dhcp or static configuration via cmdline is used.

Thus, it might be better to add binit_net_ns, binit_net_domain variables.

@unqueued
Copy link
Contributor Author

unqueued commented Mar 19, 2020

@dywisor thanks! I agree, it would be better to just have binit_net_ns and binit_net_domain variables. I will push something soon.

@unqueued
Copy link
Contributor Author

unqueued commented Mar 20, 2020

I have started again based on feedback, and if you want to take a look, I pushed it to: dns-3 for now.

@unqueued
Copy link
Contributor Author

unqueued commented Mar 7, 2023

@dywisor @slashbeast

OK, I pushed to

https://github.com/unqueued/better-initramfs/tree/dns

Now, not just is dns accepted from the dhcp server, but the dns servers can be overriden with binit_net_ns, as well as the domain with binit_net_domain flags

I can rebase it also since it looks like it's a bit behind.

@fff7d1bc
Copy link
Owner

If you have another branch (dns instead of dns-feature) can you update this pull request or otherwise load the dns-feature with the changes you'd like to be merged?

@unqueued
Copy link
Contributor Author

unqueued commented Apr 17, 2023

@slashbeast Ok, it has been four years, but I reviewed everything and updated it. When binit_net_addr=dhcp is set, then the dns servers provided by the dhcp server will be used, otherwise multiple binit_net_nss can be set to set your own dns servers, and they will override anything provided by the dhcp server. I also included #49 as well, for link-local support, since it is usually included with dhcp clients and is expected behavior.

@unqueued
Copy link
Contributor Author

If this is getting overly complicated, I could just have it so that all of the network settings are overriden when binit_net_addr is set to dhcp

@unqueued
Copy link
Contributor Author

@slashbeast I trimmed it down quite a bit, if you want it. I'm currently using it because I want to have the option of 1) using curl to invoke ntfy.sh to alert me when one of my machines boots, and 2) minimal upnp client, which is really helpful if you are behind NAT. Upnp is simple enough to just need bash and curl.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants