[ltp] Getting full hostname from DHCP
Edi Weitz
linux-thinkpad@www.bm-soft.com
21 Jun 2002 00:03:58 +0200
Eric Jorgensen <alhaz@xmission.com> writes:
> On 13 Jun 2002 00:36:35 +0200 Edi Weitz <edi@agharta.de> wrote:
> > I'm using DHCP at home as well as when I'm visiting customers of
> > mine and it is started with the -H option to set the hostname of
> > my laptop. However, no matter where I am I only get the first part
> > of the hostname, i.e. 'bird' instead of the FQDN 'bird.agharta.de'
> > for example.
>
> This behavior is correct. That is to say, it is standards compliant.
>
> > This isn't a problem at home because my domain is in
> > /etc/resolv.conf, but it is a problem when I'm not at home,
> > especially for apps like Apache or Postfix which seem to rely on
> > fully qualified hostnames.
> >
> > Any ideas how to fix this? Is this a problem of the DHCP server(s)
> > or is it related to my set-up?
>
> You can fix this symptom by defining the domain name on the
> DHCP server. Of course, at work you will probably have to ask your
> kind network administrators to make the change for you.
>
> In ISC DHCPD, you would define something like this:
>
> option domain-name "areb.org";
> option domain-name-servers 198.60.22.2, 198.60.22.22, 207.78.169.150;
>
> And then, most DHCP clients will apply this information to
> your local resolv.conf. Certainly dhclient does for me on
> debian/woody, not sure about others. Other popular possibilities are
> isc-dhcpcd and pumpd, not to mention udhcpc, etc.
[Sorry, I wasn't able to answer earlier.]
Thanks for your reply. It turns out that I didn't look into the
problem exactly enough. Fact is that even when I'm not at home my
/etc/resolv.conf is modified so that it reflects the network I'm
currently in. Nevertheless there is a problem with apps like Apache
and Postfix. It goes like this:
The distro that I'm using (Gentoo) has an init script that sets the
hostname statically before any of the network init scripts have been
started. Thus, the hostname is set to 'bird.agharta.de' (which is my
laptop's name when I'm at home). If I'm at home this is fine, but if
I'm "on the road" this doesn't work: The DHCP server sets my hostname
to, say, 'dyn164' and modifies my resolv.conf to include the line
'search dbdmedia.de', i.e. my FQDN would be 'dyn164.dbdmedia.de'. But
/bin/hostname will still answer with 'dyn164' and this is what Postfix
is complaining about:
Jun 20 16:24:51 dyn164 postfix[6044]: warning: My hostname dyn164 is not a fully qualified name - set myhostname or mydomain in /etc/postfix/main.cf
Am I supposed to write a hostname init script that starts after the
network has been initialized and calls /bin/hostname with a fully
qualified hostname determined from /etc/resolv.conf, something like
this:
#!/bin/sh
FIRST=`/bin/hostname`
REST=`perl -n -e 'print $1 if /^search (.*)/' /etc/resolv.conf`
hostname "$FIRST.$REST"
I think that would the trick, but I wonder if this is the correct way
to do it.
Thanks,
Edi.
----- The Linux ThinkPad mailing list -----
The linux-thinkpad mailing list home page is at:
http://www.bm-soft.com/~bm/tp_mailing.html