FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > Ubuntu > Kubuntu User

 
 
LinkBack Thread Tools
 
Old 09-01-2012, 05:28 AM
Bob Proulx
 
Default domain name

Glenn English wrote:
> Let's see if I've got this straight...
>
> Debian squeeze gets the host's domain name from the first
> non-comment or non-empty line of /etc/hosts?? If it likes
> that line??

No. That is incorrect. Debian sets the hostname from /etc/hostname.
This is done at boot time in the /etc/init.d/hostname.sh script. This
is called during single user boot time from /etc/rcS.d/S??hostname.sh
symlink which will have a system dependent ordering number.

Once hostname is set using the sethostname(2) kernel system call

man 2 sethostname

then later the hostname may be queried using gethostname(2), most often
by programs but also by scripts using the 'hostname' program.

> Not from /etc/hostname

Yes from /etc/hostname. As described above.

> and not from the "kernel.domainname = "
> line in /etc/sysctl.conf? ("kernel.domainname = example.com" is
> that line, commented out, in my recently installed squeeze.)

Definitely not.

> And not from /etc/resolv.conf? Or does it rely on DNS?

DNS is used for the ill conceived 'hostname -f' option. Whoever wrote
that code should be stripped of any street cred. It is terrible.
Original Unix systems did not have that option. I can't tell you how
many times I have rescued systems that had their hostname *set* to
"-f" because someone ran "hostname -f" on them. Blech.

The way 'hostname -f' works is by looking for the first IP address it
can find associated with the first network interface that it can
find. Note that the system may have many of both. But with the first
one it finds it tries to do a DNS reverse lookup of the IP address.
If that name is found in DNS then it reports that name as the fully
qualified domain name. That may be okay for a very large number of
typical systems but it is also completely incorrect for many valid
systems with more IP addresses than just one and more network
interfaces than just one.

Note that a perfectly valid configuration may specify the hostname as
a fully qualified domain name. Many BSD systems are set that way.
And BSD is the progenitor of networking. So I have that a lot of good
weight. In which case if the hostname is set to a fully qualified
domain name then there is no need for a DNS lookup and none is done.
I always used to set hostnames to be FQDNs. It works great for single
domain systems. But these days I have so many multi-domain systems
that I don't do that anymore.

Hosts have network interfaces. Perhaps zero of them. Perhaps one.
Perhaps two. Perhaps many network interfaces.

Network interfaces have IP addresses. Perhaps zero of them. Perhaps
one of them. Perhaps many IP addresses.

IP addresses have reverse DNS names associated with them. PTR
records. They should have only one. But they might actually have
many PTR records for any given IP address. When looking up an IP
address it is possible that you will get multiple names returned.

As you can see the above tree of information might be larger than the
simple one-to-one mapping that the hacks that created 'hostname -f'
planned for when they added that feature. Sometimes much larger.

> I needed to change a domain name this morning on a computer
> I'm working on, and I was told to do those different things
> from several different websites. Setting it in /etc/hosts seems
> to have worked.

If all you changed was /etc/hosts then it is likely that your change
is incomplete.

Also, what mail transfer agent are you using? Postfix? Exim? Almost
certainly one of those will need a tweak too.

> Why is this trivial task so obscure?

Because it pulls together information from several different and
independent programs that are not related to each other except by all
running on the same machine.

> I must be missing something big time. hostname was coming up with
> the right answer, but hostname -f kept saying "Name or service not
> known". Can anyone tell me what I've got wrong? And the Debian way
> of setting the domain name? (It's working now, AFAIK, but I'd like
> to set it correctly...)

* /etc/hostname

Debian uses /etc/hostname to set the network and it is called from the
/etc/init.d/hostname.sh script. Red Hat uses /etc/sysconfig/network
to set the HOSTNAME=something.example.com variable called from
someplace different in their startup sequence. So at the very start
you need to change the appropriate file. Debian encourages using only
the short name but using the FQDN as the hostname is okay.

* /etc/hosts

Many modern systems associate the hostname with 127.0.1.1 instead of
either 127.0.0.1 or a public IP address such as 192.0.43.10. This is
to solve a problem. Mobile devices typically do not always have
networking enabled. Even desktops may have networking disabled for at
least some of the time. If a public address such as 192.0.43.10 is
used then programs such as mailer transfer agents and dns resolvers
and others have errors while the network is offline. So using the
public address in /etc/hosts is problematic. (Although perfectly fine
for servers and desktops that are always online.)

And alternatively using 127.0.0.1 is problematic because then instead
of the desired name 'hostname -f' would return "localhost" or possibly
"localhost.localdomain" depending upon what is in /etc/hosts. And if
the host is exchanging information such as hostnames with peers you
definitely want to avoid passing localhost as the hostname but want it
to use a name that will map through dns back to the public IP. So in
the end associating 127.0.1.1 for the local host name in
/etc/hosts really makes a lot of sense.

The localhost.localdomain is a hack / trick to make all of the system
configuration internally consistent with a private configuration in
isolation from a public network. That's great. But if you have a
public name and IP address then you would use it instead.

* /etc/mailname

This is a Debian specific file that is intended for configuring the
mail transport agent in a generic way. It can be used for either exim
or postfix.

* /etc/postfix/main.cf

I really only know Postfix so will only talk about it. Upstream
Postfix expects the hostname to be a FQDN. If it is then that fine
and no further configuration is needed. But if the hostname is a
short name then postfix needs to be told about it. Postfix uses it to
determine the domain name. Debian has patched Postfix so that it may,
if configured to do so, use /etc/mailname to set the myorigin
variable. This mostly works but I find it better to simply set
myhostname to the FQDN. So edit that file and set the myhostname
variable to the FQDN.

If you are using Exim then you will need to understand what needs to
be done for Exim.

* /etc/resolv.conf

This file controls setting the nameservers and the domain search
path. There are some other unnecessary things that can be set there
too. I recommend using the 'resolvconf' package and then letting it
configure /etc/resolv.conf. I also think you should run a local
caching nameserver too. Assuming that you would have two lines in
this file.

nameserver 127.0.0.1
search example.com subdomain.example.com

You might also see "0.0.0.0" used there as a alias for 127.0.0.1. The
reason is an obscure bug long fixed in older systems. Now it doesn't
matter.

The search line does two things. The first entry on the line is used
as the default domain name. And the entire list is used to search
when doing a dns lookup. So setting the default domain name as the
first field of the search line will set the system's current domain
name, if the hostname isn't a FQDN already, in which case the value
there is highest priority.

Some guides will have you set "domain example.com" too. That is
fine. But it is the older part of the configuration which has been
replaced by the search configuration. Since the search configuration
supersedes the domain configuration I always prefer to set search only
and nothing else. Setting both isn't DRY (don't repeat yourself) and
redundant. It is almost always better to set configuration in only
one place and not multiple places.

And that is pretty much all that is needed to rename a system to a new
hostname. I reboot to ensure that all daemons are restarted using the
new hostname. But strictly speaking that isn't needed if everything
is restarted.

If you have questions then ask. The above was simply an off the top
of the head description and I am sure I didn't do a great job of it.

Good luck!
Bob
 
Old 09-01-2012, 08:53 AM
Joe
 
Default domain name

On Fri, 31 Aug 2012 18:35:25 -0600
Glenn English <ghe@slsware.com> wrote:

> I think I've got it, and it makes sense, in retrospect.
>
> Here's a good site:
>
> http://www.microhowto.info/howto/persistently_change_the_hostname_of_the_local_mach ine_on_debian.html
>
> What happens, apparently, is that nothing ever sets the
> domain name at boot. When the kernel wants an FQDN, it
> does a machine-name lookup from /etc/hostname then looks
> in /etc/hosts for the machine-name. And it expects to find
> the machine-name and the FQDN, on one line. Maybe near the
> top -- I haven't looked into that.
>
> And if this doesn't work, it goes to DNS for a reverse look
> up the of IP. If the DNS lookup returns something with a
> machine-name that doesn't match /etc/hostname, it returns
> an error.
>
> I think this is how it works. From the futzing I've done,
> that seems to at least be close to what happens...
>
> This all strikes me as a little complex, but it works, and
> there aren't several places where there an admin could put
> a wrong domain name. And it doesn't happen too often, so I
> guess it's OK.
>
> Sure would be nice, though, if this were clearly and simply
> laid out in some documentation somewhere. I found lots of
> places that said that the domain name is *not* to be stored
> in /etc/hostname, but it was difficult to find where it *is*
> to be stored...
>

The apparently haphazard means of assigning a domain name reflects
the much lower importance attached to 'domain' outside the
Microsoft Active Directory world. If you send email on behalf of a
number of DNS domains, which of them, if any, does your workstation
'belong' to? If your workstation is accessible from the outside world,
it may be reached by URLs based on a number of different DNS domains.
Again, which is the 'correct' one?

Possibly some of the confusion arises from Microsoft's use of the word
'domain' to mean an administrative and security grouping of business
computers, when the word already had a perfectly valid meaning in IT
terms. But the DNS structure has also been tied into this system since
Active Directory appeared, adding to the confusion between two very
distinct concepts. It is inconceivable that an MS domain member
computer should not have a domain name. Away from Active Directory, a
'domain' is a DNS and therefore network communication concept, and it
doesn't necessarily make sense for a workstation to have a DNS domain
associated with it.

--
Joe


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 20120901095334.46397a69@jretrading.com">http://lists.debian.org/20120901095334.46397a69@jretrading.com
 
Old 09-01-2012, 05:06 PM
Andrei POPESCU
 
Default domain name

On Vi, 31 aug 12, 23:28:39, Bob Proulx wrote:

[snip]

+100, informative

> If you have questions then ask. The above was simply an off the top
> of the head description and I am sure I didn't do a great job of it.

You're too humble...

Kind regards,
Andrei
--
Offtopic discussions among Debian users and developers:
http://lists.alioth.debian.org/mailman/listinfo/d-community-offtopic
 
Old 09-01-2012, 07:11 PM
Glenn English
 
Default domain name

On Sep 1, 2012, at 2:53 AM, Joe wrote:

> The apparently haphazard means of assigning a domain name reflects
> the much lower importance attached to 'domain' outside the
> Microsoft Active Directory world.

Well, that's an interesting thought. A domain, to me, means where
the DNS of the world goes looking for my server. I'm self taught
(from O'Reilly books, etc.) on Linux, and I've had next to nothing
to do with MicroSoft anything. A domain is quite important to a server
on the 'Net -- it never occurred to me that it meant something else in
the MS world.

> Again, which is the 'correct' one?

To me, the one I rent from my registrar. Or one of the virtuals I host --
wherever DNS is trying to go.

Thanks for the info...

--
Glenn English




--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 02047FC9-B5EE-4632-A595-214C81228DBA@slsware.com">http://lists.debian.org/02047FC9-B5EE-4632-A595-214C81228DBA@slsware.com
 
Old 09-01-2012, 08:30 PM
Glenn English
 
Default domain name

On Aug 31, 2012, at 11:28 PM, Bob Proulx wrote:

> Debian sets the hostname from /etc/hostname.

I never had a problem with the hostname. It was the domain name
that was making me crazy.

>> and not from the "kernel.domainname = "
>> line in /etc/sysctl.conf? ("kernel.domainname = example.com" is
>> that line, commented out, in my recently installed squeeze.)
>
> Definitely not.

Apparently not :-) I tried, but couldn't get it to have any effect
on anything. It does make me wonder, though, what that line is doing
there. It looks like it should (used to?) set the domain name...

> DNS is used for the ill conceived 'hostname -f' option. Whoever wrote
> that code should be stripped of any street cred. It is terrible.

It may be terrible code, but that doesn't seem to be how it works
here. hostname -f returns the fqdn of the host in question, even if
its DNS server is set incorrectly (/etc/hosts is correct, and I've
set the resolver to look first at hosts, then DNS).

> That may be okay for a very large number of
> typical systems but it is also completely incorrect for many valid
> systems with more IP addresses than just one and more network
> interfaces than just one.

I've got systems with more than one interface, and I've never run into
that problem. I'm guessing that's just because I've always set up eth0
to be the 'Net facing interface. A long time ago, I wrote a big shell
script to init iptables, and the way it's written, eth0 *has* to point
to the 'Net. Just lucky, I guess :-)

> Note that a perfectly valid configuration may specify the hostname as
> a fully qualified domain name. Many BSD systems are set that way.
> And BSD is the progenitor of networking.

Yup. But the Debian dox say very clearly not to do that. It does seem to
work pretty well, though. I've set up several machines that way.

But I don't have any idea what's going on down in the kernel code. I was
thinking I might be doing something that wouldn't work someday or was using
extra CPU cycles or something. I just wanted to know the *one* place the
kernel goes to most efficiently to determine the Internet domain name. As
best I can tell, that place is a properly written /etc/hosts.

> If all you changed was /etc/hosts then it is likely that your change
> is incomplete.

Quite possibly, but it seems to have done the job. AFAIK, it's the only
place, outside of some server configs, where the domain name is mentioned.

> Also, what mail transfer agent are you using? Postfix? Exim? Almost
> certainly one of those will need a tweak too.

Postfix. And there's a domain name in its config for sure.

> Because it pulls together information from several different and
> independent programs that are not related to each other except by all
> running on the same machine.

That's very true. But if I were writing all that stuff, the host's domain
name relevant to TCP/IP would be in one place, and everybody would go there
(or to a kernel call) to get it. It's all too easy to have the kernel and
Postfix thinking they're running at different domains.

> Many modern systems associate the hostname with 127.0.1.1

I ran across that -- IIRC, it's supposed to be what I put in hosts
when the host's IP is dynamic or it has no domain. And it can cause
troubles when the host is a server on the 'Net with a static IP and
a domain.

> And alternatively using 127.0.0.1 is problematic because then instead
> of the desired name 'hostname -f' would return "localhost" or possibly
> "localhost.localdomain" depending upon what is in /etc/hosts.

Seems to me it should return "localhost" in that case, because 127.0.0.1
*is* localhost.

> The localhost.localdomain is a hack / trick to make all of the system
> configuration internally consistent with a private configuration in
> isolation from a public network. That's great. But if you have a
> public name and IP address then you would use it instead.

Depending of whether you wanted to talk to yourself or somebody outside
the host?? Or might it be more efficient to have a localhost IP to use
for internal tasks??

> If you have questions then ask. The above was simply an off the top
> of the head description and I am sure I didn't do a great job of it.

Thanks hugely for the long, detailed response. But you seem to hold a
couple opinions that I don't think are optimally correct on Debian. Or
maybe they are. I really don't know -- I haven't looked at the source.
Whatever, both ways seem to work. Maybe someday the Debian documentation
will describe this process more clearly...

If you *do* know the code, and it indicates that my impression(s) are
wrong, I'd love to hear about it.

Thanks again.

--
Glenn English




--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 2BE5006F-B2B1-4D09-BF96-BBD0B40DF734@slsware.com">http://lists.debian.org/2BE5006F-B2B1-4D09-BF96-BBD0B40DF734@slsware.com
 
Old 09-01-2012, 08:34 PM
Bob Proulx
 
Default domain name

Glenn English wrote:
> What happens, apparently, is that nothing ever sets the
> domain name at boot.

But a domain name isn't really important to the server kernel itself.
A domain name is a piece of information that *others* need. But it
isn't needed nor really used by the local server. The kernel doesn't
care about it at all.

> When the kernel wants an FQDN,

This is a very important point and it is worth exploring. When do you
think the kernel ever wants a FQDN? Please let's talk about it and I
am sure we will find that this has nothing to do with the kernel.

The number one piece of software on a system that needs to know the
domain name is the mail transfer agent. Usually Postfix or Exim but
could be Sendmail or others. They need to know this to generate a
reply address, the "From:" address, so that others can reply to the
email.

> it does a machine-name lookup from /etc/hostname

No. That file is only used at boot time to set the hostname. It is
distro specific. Other systems use different files.

> then looks in /etc/hosts for the machine-name.

Whether a dns lookup checks /etc/hosts or not is dependent upon the
configuration in /etc/nsswitch.conf (network services switch) which
would normally list this:

hosts: files dns

But if avahi is installed will list some other problematic items that
I am going to ignore for now. Also NIS/YP if installed will add other
search locations. But given the above setting it will look in
/etc/hosts first and then if not found will continue to do a dns
lookup second.

> And it expects to find the machine-name and the FQDN, on one
> line. Maybe near the top -- I haven't looked into that.

The format of the /etc/hosts file is a line by line linear search from
top to bottom for the desired information. Reading of the file stops
as soon as the data requested is found.

As far as I know the kernel never needs to know the domain name and
the kernel never does a dns lookup. The kernel only holds the value
of the hostname. You can set the value. You can retrieve the value.
And that is the entire involvement of the kernel in the issue.

Random userland application programs want to know the domain name
(such as the mail transfer agent) and these non-kernel userland
programs will do various random things such as doing dns lookups
trying to deduce a value for it. But they are not the kernel.

Postfix for example gets the hostname and uses it to set its
configuration for the myhostname and mydomainname variables that it
uses when writing mail headers. If the hostname contains a FQDN then
that string is used to set those variables. If not then it sets
mydomain to "localdomain".

Since these days it is encouraged to set the hostname to a short name
without any FQDN since a host might be operating in multiple domains
it means that most commonly postfix won't have a FQDN to get that
information from and will default to "localdomain". Since that isn't
desirable I usually go ahead and set the Postfix myhostname variable
to the FQDN explicitly so that it can extract both myhostname and
mydomainname as desired. (I didn't say "correctly" since there are
many valid configuration possible and it is a judgement as to which is
best. But as desired in my case means as I desire it. [smile])

> And if this doesn't work, it goes to DNS for a reverse look
> up the of IP. If the DNS lookup returns something with a
> machine-name that doesn't match /etc/hostname, it returns
> an error.

Yes.

> I think this is how it works. From the futzing I've done,
> that seems to at least be close to what happens...

I just want to note that I wrote an explanation of this in my other
reply but it appears that you did not read it?

> This all strikes me as a little complex, but it works, and
> there aren't several places where there an admin could put
> a wrong domain name. And it doesn't happen too often, so I
> guess it's OK.

I could definitely see some improved documentation to help people
understand all of the concepts. It seems perfect for a wiki page.

> Sure would be nice, though, if this were clearly and simply
> laid out in some documentation somewhere. I found lots of
> places that said that the domain name is *not* to be stored
> in /etc/hostname, but it was difficult to find where it *is*
> to be stored...

It is perfectly fine to put a FQDN in /etc/hostname. It is how a lot
of machines are configured. However Debian discourages it. It is a
different way of thinking. For example these days a machine might be
serving web pages for a dozen different web sites all in different
domains. The server system itself would be operating in several
domains. Send it a request for an unconfigured domain and by default
it will send back and error page that will often tell us the
underlying hostname and domain. (For example sending a request to the
IP address of www.debian.org but with a different hostname will tell
you that it is running on "senfl" and nicely a pointer to more
information about it since Debian is such an open project. Other
sites do different things.)

So forcing a single overriding domain upon everything running there is
a little restrictive. A person might feel claustrophobic! Therefore
thinking about things differently, not using a FQDN as the hostname,
and configuring software to be more multidomain aware is a more
general purpose way of thinking about multi-use systems. I think that
is why Debian discourages using the FQDN as the hostname. But that
doesn't mean that doing so anyway is incorrect. Also a lot of
upstream software (such as Postfix) expects the hostname to be a FQDN.

Bob
 
Old 09-01-2012, 09:15 PM
John Hasler
 
Default domain name

Glenn writes:
> I just wanted to know the *one* place the kernel goes to most
> efficiently to determine the Internet domain name.

The kernel has no interest in domain names. It deals only in IP
numbers. Dealing with DNS is the job of a resolver running in user
space.

> But if I were writing all that stuff, the host's domain name relevant
> to TCP/IP would be in one place...

A machine can be in more than one domain.
--
John Hasler


--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 87fw71igw7.fsf@thumper.dhh.gt.org">http://lists.debian.org/87fw71igw7.fsf@thumper.dhh.gt.org
 
Old 09-01-2012, 09:49 PM
Glenn English
 
Default domain name

On Sep 1, 2012, at 3:15 PM, John Hasler wrote:

> The kernel has no interest in domain names. It deals only in IP
> numbers. Dealing with DNS is the job of a resolver running in user
> space.

Thanks. I didn't know that -- makes sense. But it raises a question in
my mind: Who does, beside servers? Just 'hostname'?

I think I came into the TCP/IP networking business a little late. Was
there ever a time when there were no domains, just IPs? That could
explain a lot to me about why the domain name is so hard to get to...

> A machine can be in more than one domain.

I don't understand that. I've got several domains' nameserver records
pointed at my server, serving a number of protocols. But the server
itself is in only one domain. Apache and Postfix and Bind all handle the
different domains, but I think of all of them as virtual domains, not the
one true domain that my server is part of.

Am I thinking wrong? Or is it possible somehow for a machine to have 2 FQDNs?
I've never considered that. And I can't think of how to configure things so
'hostname --fqdn' could answer with 2 strings...

--
Glenn English




--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: D5EE0F34-4BDA-413F-BBFB-081238213E66@slsware.com">http://lists.debian.org/D5EE0F34-4BDA-413F-BBFB-081238213E66@slsware.com
 
Old 09-01-2012, 09:53 PM
Bob Proulx
 
Default domain name

Bob Proulx wrote:
> Glenn English wrote:
> > And it expects to find the machine-name and the FQDN, on one
> > line. Maybe near the top -- I haven't looked into that.
>
> The format of the /etc/hosts file is a line by line linear search from
> top to bottom for the desired information. Reading of the file stops
> as soon as the data requested is found.

It turns out that this is configurable.

man host.conf

The file /etc/host.conf contains configuration information specific to
the resolver library. ...

multi Valid values are on and off. If set to on, the resolv+ library
will return all valid addresses for a host that appears in the
/etc/hosts file, instead of only the first. This is off by
default, as it may cause a substantial performance loss at sites
with large hosts files.

The default in Debian is "multi on" and so it won't stop at the first
matching line. (Which seems fine since the /etc/hosts file is very
short on modern systems that use the domain name system.) That memory
must have come from another system perhaps quite long ago.

Bob
 
Old 09-01-2012, 10:02 PM
Glenn English
 
Default domain name

On Sep 1, 2012, at 3:53 PM, Bob Proulx wrote:

> It turns out that this is configurable.
>
> man host.conf

Silly me. And I always thought /etc/resolv.conf' was the resolver configuration.
I've got a little reading to do...

--
Glenn English




--
To UNSUBSCRIBE, email to debian-user-REQUEST@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmaster@lists.debian.org
Archive: 37345CE8-2F6F-4CDA-B164-C3B8DB5115C5@slsware.com">http://lists.debian.org/37345CE8-2F6F-4CDA-B164-C3B8DB5115C5@slsware.com
 

Thread Tools




All times are GMT. The time now is 02:59 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org