Solved Hostname resolution when installing FreeBSD

Mjölnir

Daemon

Reaction score: 1,503
Messages: 2,114

When I did back then, either the nohook option wasn't there yet or I missed it in the documentation pile, or I didn't manage getting it to work, so I had to figure out some means to protect the original /etc/resolv.conf file.

This apparently happens to many people. So maybe it is a documentation problem of some essential information that should be mentioned prominently on the first page actually being hidden in some appended document referenced only by footnote.
It took me days(weeks?) to find out about the existence of this resolvconf(8)... /etc/resolv.conf was magically changing it's contents... Heck, I was so frustrated that "it" insisted to change my working config... of course one tries to circumvent this. I did as well. I don't remember how I found out (crawling though "See Also" links in manpages?) or if someone told me.
As for hostname resolution, I can't get this working via installerconfig. If I don't have an installerconfig and jump into the shell I can access the required hosts by name. I did include 'dhclient em0' in /etc/rc.local to achieve this.
IIUC either dhclient(8) or the service(8) script should set hostname resolution via resolvconf(8) (into resolv.conf(5)), unless you explicitely deny that (see nohook mentioned above). Maybe try service netif start em0 instead of calling dhclient(8) directly. This will also set the appropriate routes. Do you also have an active WLAN interface? IIRC the last activated interface sets the default route; you can override that via sysrc defaultrouter="IPv4.default.router" (this sets that into rc.conf(5)).
 

Snurg

Daemon

Reaction score: 592
Messages: 1,349

Mjölnir
Maybe then it would be a good idea to complain upstream (ISC?), to add a small comment in the main dhcp man page.
This probably would resolve one of the main annoyances for most users...
Would you be willing to take care of that?
 

Mjölnir

Daemon

Reaction score: 1,503
Messages: 2,114

Maybe then it would be a good idea to complain upstream (ISC?), to add a small comment in the main dhcp man page. This probably would resolve one of the main annoyances for most users...
Agreed.
Would you be willing to take care of that?
Short answer: No. Long answer: I had to start to keep track of issues that annoy & bug me, add them into my todo-list & prioritize them, and take notes into a journal ("log book") how to fix and/or patch (or ideas about that) & any related notes. Now I'm doing that semi-professional with KDE's PIM suite Kontact/KOrganizer, where I'm already lagging behind with a 8-month backlog in the tasks/todo-list, although I frequently supply bug reports, whenever I can incl. patch. They're jumping bright red into my face every day when I read my e-mail & RSS feeds & scream "FIX ME, dude!". You guessed right that the main reason is me refusing to apply more discipline & wasting less time here, but that's another story...

So what could I do better than to encourage you to do that yourself? It was your idea, go for it. I would recommend to file a bug report to FreeBSD, asking that a native english speaker adds that small but valuable note to the man page, and hope that the maintainer(s) responsible on the FreeBSD side will forward that upstream to ISC. You can also note that in your bug report.
 

Snurg

Daemon

Reaction score: 592
Messages: 1,349

Hmm Mjölnir ...
I just got an idea when I read that 😁
You know, I asked for poudriere/synth's properties...
it is actually intended for bugfix patches that are not (yet) integrated.

Imagine a menu option something like "Hall of Shame", and when you click it, a page appears with a list of bugs+patches, each one with a checkbox.
Every patch you check will be integrated via either synth or poudriere.
A link to the respective PR included, for patch testing feedback.

This is what I want :)
Maybe such might help one or the other particularly annoying bug get fixed quicker... :D
 

chk.jxcn

Member

Reaction score: 4
Messages: 36

So what would I need to do to add pkgs? As far I can see my 'resolv.conf' is not accessible so am unable to contacts pkg.freebsd.org'. Is this because 'pkg add xyz' is running in chroot?
Because script is running under chroot mode, so the reason of resolve hostname fail is bsdinstall can't copy resovle.conf.
Try follow:
1. delete resolv.conf and link it to /tmp/resolv.conf (so dhclient could overwrite it before create folder /tmp/bsdinstall_etc)
2. add 'ifconfig_em0='DHCP' to /etc/rc.conf (then bsdinstall can copy correct content of resolv.conf to install dir)

I guess this could help but I not test yet.

Sorry, I make a mistake, the file /tmp/resolv.conf can't create before DHCP, it can't works.
Please run dhclient in /etc/installerconfig:

touch /tmp/bsdinstall_etc/resolv.conf
ifconfig em0 up
dhclient em0
#!
pkg install something
 
OP
B

balanga

Son of Beastie

Reaction score: 217
Messages: 4,024

I found out that running dhclient em0 as part of /etc/installerconfig sorts things out. No need for anything else. Not entirely sure how it works, but I guess it must have something to do with a 'chrooted' environment.
 

T-Daemon

Daemon

Reaction score: 873
Messages: 1,749

I found out that running dhclient em0 as part of /etc/installerconfig sorts things out. No need for anything else.
That won't be enough. A fresh installer image comes with no /tmp/bsdinstall_etc/resolv.conf. The reason why you don't experience any problems now is that file has been created from earlier attempts. That file must be present before running dhclient(8).

I experimented more on DHCP network interface configuration and populating resolv.conf on a fresh installer image. The following settings seems to be enough, they create a resolv.conf file and request an IP for the network interface and name server addresses from the DHCP server. No other settings are necessary.

/etc/rc.local
Code:
# resolv.conf from DHCP ends up in here, so make sure the directory exists
mkdir /tmp/bsdinstall_etc

# Add here the following  two lines after the above command
touch /tmp/bsdinstall_etc/resolv.conf
dhclient em0
Setting dhclient em0 in /etc/installerconfig is not the right place to put. Network device configuration and name resolving of the installer images system shouldn't be mixed with commands targeting the to be new installed and configured system, they should all go into /etc/rc.local. It works but it's bad scripting practice.

but I guess it must have something to do with a 'chrooted' environment.
chk.jxcn is in error, the installer images system network configuration has nothing to do with a chrooted environment. See for reason third sentence, after the first quote.
 

chk.jxcn

Member

Reaction score: 4
Messages: 36

That won't be enough. A fresh installer image comes with no /tmp/bsdinstall_etc/resolv.conf. The reason why you don't experience any problems now is that file has been created from earlier attempts. That file must be present before running dhclient(8).

I experimented more on DHCP network interface configuration and populating resolv.conf on a fresh installer image. The following settings seems to be enough, they create a resolv.conf file and request an IP for the network interface and name server addresses from the DHCP server. No other settings are necessary.

/etc/rc.local
Code:
# resolv.conf from DHCP ends up in here, so make sure the directory exists
mkdir /tmp/bsdinstall_etc

# Add here the following  two lines after the above command
touch /tmp/bsdinstall_etc/resolv.conf
dhclient em0
Setting dhclient em0 in /etc/installerconfig is not the right place to put. Network device configuration and name resolving of the installer images system shouldn't be mixed with commands targeting the to be new installed and configured system, they should all go into /etc/rc.local. It works but it's bad scripting practice.


chk.jxcn is in error, the installer images system network configuration has nothing to do with a chrooted environment. See for reason third sentence, after the first quote.
Hi T-Daemon


For the chroot, that's my mistake, I ever thought bsdinstall will not copy /etc/resolv.conf to chrooted environment in unattended installation, but it's wrong.
 
OP
B

balanga

Son of Beastie

Reaction score: 217
Messages: 4,024

That won't be enough. A fresh installer image comes with no /tmp/bsdinstall_etc/resolv.conf. The reason why you don't experience any problems now is that file has been created from earlier attempts. That file must be present before running dhclient(8).

I experimented more on DHCP network interface configuration and populating resolv.conf on a fresh installer image. The following settings seems to be enough, they create a resolv.conf file and request an IP for the network interface and name server addresses from the DHCP server. No other settings are necessary.

/etc/rc.local
Code:
# resolv.conf from DHCP ends up in here, so make sure the directory exists
mkdir /tmp/bsdinstall_etc

# Add here the following  two lines after the above command
touch /tmp/bsdinstall_etc/resolv.conf
dhclient em0
Setting dhclient em0 in /etc/installerconfig is not the right place to put. Network device configuration and name resolving of the installer images system shouldn't be mixed with commands targeting the to be new installed and configured system, they should all go into /etc/rc.local. It works but it's bad scripting practice.


chk.jxcn is in error, the installer images system network configuration has nothing to do with a chrooted environment. See for reason third sentence, after the first quote.
T-Daemon, I must be missing something since I tried this several times and if I had dhclient em0 just in /etc/rc.local I was unable to ping any host by name. It was only when I put this command in /etc/installerconfig that host names were resolvable. I understand that is not the way I'm supposed to do it, but it's the only way I can make it work.
 
Top